Skip to content

Instantly share code, notes, and snippets.

@amalgjose
Created March 6, 2015 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amalgjose/6c81abebc7bb45e2a5d8 to your computer and use it in GitHub Desktop.
Save amalgjose/6c81abebc7bb45e2a5d8 to your computer and use it in GitHub Desktop.
Python method to find the count of unique elements in a list.
__author__ = 'Amal G Jose'
count = {}
data_list = ['apple', 'apple', 'orange', 'mango', 'apple', 'grapes', 'banana', 'banana']
for value in data_list:
if value in count.keys():
count[value] += 1
else:
count[value] = 1
print count
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