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 197 views
2 answers 280 views
2 answers 259 views
2 answers 244 views
1 answer 203 views
1 answer 225 views
1 answer 245 views
...