How to remove duplicate words from a string in Python

1 Answer

0 votes
def unique_words(lst):
    uniquelst = []
    [uniquelst.append(w) for w in lst if w not in uniquelst]
    return uniquelst

s = "node.js python c javascript c++ c node.js c++"
s = ' '.join(unique_words(s.split()))

print(s)
 
      
     
'''
run:

node.js python c javascript c++
     
'''

 



answered Mar 27, 2020 by avibootz
...