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

1 Answer

0 votes
s = 'python java c c++ java c++ python rust rust rust'

total_unique_words = len(set(s.split(' ')))

print(total_unique_words)


'''
run:

5

'''

 



answered Sep 20, 2024 by avibootz

Related questions

1 answer 199 views
1 answer 204 views
1 answer 211 views
1 answer 191 views
1 answer 247 views
1 answer 224 views
1 answer 195 views
...