How to get only the unique words from a string in Python

1 Answer

0 votes
from collections import Counter

s = "python javascript c c++ php c++ php java javascript"

words = s.split(' ')

dict = Counter(words)

unique_words = [i for i in words if dict[i] == 1]

print(unique_words)




'''
run:

['python', 'c', 'java']

'''

 



answered Dec 31, 2021 by avibootz

Related questions

1 answer 125 views
2 answers 175 views
2 answers 158 views
2 answers 140 views
1 answer 130 views
1 answer 135 views
1 answer 161 views
...