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 115 views
1 answer 115 views
1 answer 119 views
1 answer 113 views
1 answer 153 views
1 answer 134 views
1 answer 114 views
...