In python how would i display all of the repeating words in
In python, how would i display all of the repeating words in a list? I have about 1300 words and some of them repeat. What code can i use to display the words and how much they each repeat. Thank you
Solution
word_list= \"working for success will make you a master but working for satisfaction will make you a legend\" // write any of your statement to rectify
lists= word_list.split(\" \")
lists.sort()
words_repeat = word_list.split(\" \")
words_repeat.sort()
for word in lists:
duplicate = 0
while(True):
try:
index = words_repeat.index(word)
duplicate+= 1
del words_repeat[index]
except ValueError:
if duplicate is not 0:
print(word + \" is repeated \" + str(duplicate) + \" times.\")
break
output:
a is repeated 2 times.
but is repeated1 times.
for is repeated 2 times.
legend is repeated 1 times.
make is repeated 2 times.
master is repeated 1 times.
satisfaction is repeated 1 ties.
success is repeated 1 times.
you is repeated 2 times.
will is repeated 2 times.
working is repeated 2 times.

