9951 explained code solutions for 126 technologies


pythonRemove duplicate words from string


words = 'a b c b c'.split()
uniq = list()

for word in words:
  if word not in uniq:
    uniq.append(word)

uniq_string = ' '.join(uniq)ctrl + c
'a b c b c'

sample string to remove duplicate words from

.split()

will split given string into a list of words

for word in words

iterate through all words

uniq.append(word)

append word to uniq list if it's not in the list already

uniq_string

final string without duplicate words