Last active
December 17, 2015 00:28
-
-
Save vishalsodani/5520913 to your computer and use it in GitHub Desktop.
Count frequency of items in a list using defaultdict
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
some_data = ['a','b','v','c','l','c'] | |
frequency_count = defaultdict(int) | |
for item in some_data: | |
frequency_count[item] += 1 | |
print frequency_count | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment