More information about the Underscore mailing list

[_] Python Question

Matthew Wilkes matt at
Thu Dec 17 17:47:09 GMT 2009

There are a couple of ways of doing this, the simplest I can think of  
that keeps your flow is:

from collections import defaultdict
attributes = defaultdict(dict)

attribute_data = mark.fetchall()

for i in attribute_data:

(Python 2.5 and above only)

There should be other ways using itertools.groupby, but you'd just end  
up fighting against the built-in types that way as that style expects  
you to be doing lazy evaluation which doesn't fit well here.