Python Duplicate Word Checking

python

Posted by indranil on June 1, 2021, 6:11 p.m.

a = "hi this is is the the hi this indranil the"
b = "my name is indranil "

rslt = []
def CheckWord(data, word):
    
    
    msg = ""
    if (data==[]):
        msg = "TRUE"
        
    else:    
        for i in data:
            if not (i)==word:
                msg = "TRUE"
            else:
                msg = "FALSE"
                break

    
    return msg

def GenWord(line):
    if not line[(len(line)-1):len(line)] == " ":
        line = f"{line} "
    word= []
    w = ""
    
    for i in line:
        w = f"{w}{i}"
        if i == " ":
            word.append({f'word':w[0:(len(w)-1)]})
            w = ""


    return word        

myLine = f"{a}"

 


p1 = GenWord(myLine)
for i in p1:
    chk = CheckWord(rslt, i)
    if chk == "TRUE":
        rslt.append(i)
        pass
#print(rslt)
fr = ''
for i in rslt:
    
    fr = f'{fr} {(i["word"])}'

print(fr)

 

noimg Visit Link: digitalocean.com