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?

Recommended Answers

All 2 Replies

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

Awesome, thank you Chris!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.