[_] Python Question
Matthew Wilkes
matt at matthewwilkes.name
Thu Dec 17 23:57:18 GMT 2009
This is fun, here's another, less pretty one: attribute_data = mark.fetchall() keys = (v for k,v in attribute_data) attributes = dict((key, [k for k,v in attribute_data if v == key]) for key in keys) Alternatively, if you have something like Paste available you can use its MultiDict implementation: from paste.util.multidict import Multidict attribute_data = mark.fetchall() attributes = MultiDict(v[::-1] for v in attribute_data).dict_of_lists() Anyone else want to play? Come on Tim, you know you want to. Matt