Using a dictionary to count the items in a list [duplicate]

I’m new to Python and I have a simple question, say I have a list of items:

['apple','red','apple','red','red','pear']

Whats the simpliest way to add the list items to a dictionary and count how many times the item appears in the list.

So for the list above I would like the output to be:

{'apple': 2, 'red': 3, 'pear': 1}

8 Answers
8

Leave a Comment