Re: Best/better way? (histogram)

2009-01-28 Thread Peter Otten
Bernard Rankin wrote: I've got several versions of code to here to generate a histogram-esque structure from rows in a CSV file. The basic approach is to use a Dict as a bucket collection to count instances of data items. Other than the try/except(KeyError) idiom for dealing with new

Re: Best/better way? (histogram)

2009-01-28 Thread Bernard Rankin
The simplest. That would be #3, cleaned up a bit: from collections import defaultdict from csv import DictReader from pprint import pprint from operator import itemgetter def rows(filename): infile = open(filename, rb) for row in DictReader(infile): yield

Best/better way? (histogram)

2009-01-27 Thread Bernard Rankin
Hello, I've got several versions of code to here to generate a histogram-esque structure from rows in a CSV file. The basic approach is to use a Dict as a bucket collection to count instances of data items. Other than the try/except(KeyError) idiom for dealing with new bucket names, which I