Wednesday, July 8, 2015

Count number of letter occurence


Solution 1:
list1=[1,2,1,3]
count={}

for item in list1 :
 print item
 if item not in count: #check if item is in list
  count[item]=0 #if no then set item key value 
  print count[item]
 count[item]+=1 #yes increment  
 print count[item]
print count