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 126 views
1 answer 127 views
1 answer 129 views
1 answer 121 views
1 answer 164 views
1 answer 144 views
1 answer 122 views
...