Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created March 6, 2015 16:13
Show Gist options
  • Save amalgjose/34c6182ca661fc4a9536 to your computer and use it in GitHub Desktop.
Save amalgjose/34c6182ca661fc4a9536 to your computer and use it in GitHub Desktop.
Method for finding the count of unique elements in a list. This will work only in python versions 2.7 and above
__author__ = 'Amal G Jose'
from collections import Counter
data_list = ['apple', 'apple', 'orange', 'mango', 'apple', 'grapes', 'banana', 'banana']
count = Counter(data_list)
print count.items()
print "Count of apple : ", count['apple']
print "Count of orange : ", count['orange']
print "Count of banana : ", count['banana']
print "Count of grapes : ", count['grapes']
print "Count of mango : ", count['mango']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment