[Tutor] Merging dictionaries

Benoit Thiell benoit.thiell at cern.ch
Thu Aug 7 07:21:36 CEST 2008


Dear Norman,

I would propose:

ret = {}
myvalues = []
responses = [{'a1': [1], 'a2': [1, 2, 3]}, {'a1': [0], 'a2': [0, 1, 3]}]

for response in responses:
     for answer in response.items()
         ret.setdefault(response[0], []).append(response[1])

Regards,
Benoit Thiell.




More information about the Tutor mailing list