View Single Post
Old Dec 26th, 2005, 3:59 AM   #4
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
You might want to think about using a dictionary to hold the counts of your items:
d = {}
for x in y:
    d[x] = d.get(x, 1) + 1
And perhaps giving your variables and functions longer and more descriptive names. It's all too easy to forget what does what several months down the line:
bag = {}
for item in list:
    bag[item] = bag.get(item, 1) + 1
(A bag being the technical name of the data struct your function creates.)
Arevos is offline   Reply With Quote