0
finding the count of repetition of every element in a list
Hi, I need a code that checks every element in a list and assigns a count of repetition to that element. for example: list1 = ['i' , 'be' , 'then' , 'i' , 'i' , 'then' ] and the output would be something like this: count of "i" is 3 count of "then" is 2 count of "be" is 1 #note that output will show count of all of them at once
2 odpowiedzi
+ 3
Hi! Please, show your attempt.
+ 3
Alireza Azizzadeh
1. Create an empty dictionary
2. Iterate through your list
if item not in dict, then add item as key : value =1.
if item already in dict, then value +=1
When you have finished iterating, you will have a dict containing words : occurences
print them out