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 115 views
2 answers 162 views
2 answers 145 views
2 answers 133 views
1 answer 118 views
1 answer 123 views
1 answer 151 views
...