frequency of values in a field

Josh English Joshua.R.English at gmail.com
Tue Feb 8 19:42:23 CET 2011


You could try a collections.defaultdict object with an integer as the startup value:

counts = collections.defaultdict(int)
for thing in long_list:
  counts[get_last_two_digits(thing)] += 1

This assumes get_last_two_digits is the function that provides the key you want to count by. I'm not sure what you want get_last_two_digits to look like from your post, or how you would get the long_list, which is just an iterator through your records.

Josh 



More information about the Python-list mailing list