0

Greetings. I'm a python noob and I'm stuck with some coding.

Say you have a list with a number of elements, some of which are the same. For instance:
mylist =

Is there a way to return how many times each string occurs in the list?

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by hydrobat
0

Yes there is it's pretty simple too

mylist = ['blue', 'red', 'green', 'green', 'red', 'red']

for word in set(mylist):
    print word, "appears", mylist.count(word), "times."

Hope that helps.

Chris

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.