I\'ve been whacking away at this for a while to no avail... Any help would be greatly appreciated.
I have:
[{\'event\': 0, \'voltage\': 1, \'time\':
dict_list = [{'event': 0, 'voltage': 1, 'time': 0},
{'event': 0, 'voltage': 2, 'time': 1},
{'event': 1, 'voltage': 1, 'time': 2},
{'event': 1, 'voltage': 2, 'time': 3},
{'event': 2, 'voltage': 1, 'time': 4},
{'event': 2, 'voltage': 2, 'time': 5},
]
import collections
dol = collections.defaultdict(list)
for d in dict_list:
k = d["event"]
dol[k].append(d)
print dol
if you know that your "event" keys are consecutive zero-based integers, you can use a list instead, but the extra complexity may not gain you anything.
defaultdict was added in python 2.5, but the workaround for earlier versions is not hard (see Nick D's code).