[_] Python Question
Matthew Wilkes
matt at matthewwilkes.name
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:
attributes[i[1]].append(i[0])
(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.
Matt