> Message: 4
> Date: Wed, 6 Aug 2008 21:59:40 +0200
> From: "Norman Khine" <[EMAIL PROTECTED]>
> Subject: [Tutor] Merging dictionaries
> To: tutor@python.org
> Message-ID:
> <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1
&g
Thank you all for the replies.
Norman
On 8/7/08, wesley chun <[EMAIL PROTECTED]> wrote:
> hmmm, somewhat off-topic, i was partially confused by the Subject
> line. i thought this post was about merging *dictionaries* and not
> merging the *contents of multiple dictionaries' values*.
>
> for those
hmmm, somewhat off-topic, i was partially confused by the Subject
line. i thought this post was about merging *dictionaries* and not
merging the *contents of multiple dictionaries' values*.
for those who are interested in the former, you use the update()
method and here is an example:
>>> d1 = d
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.
On Wed, Aug 6, 2008 at 3:59 PM, Norman Khine <[EMAIL PROTECTED]> wrote:
> So far I have an output which puts in a list all the user's responses, such as
>
> responses = [{'a1': [1], 'a2': [1, 2, 3]}, {'a1': [0], 'a2': [0, 1, 3]} ]
>
> Is this an efficient way to do this, say for example I hav
Hello,
I am trying to figure out the best way to add results from a poll module that I
have working, but am a bit stuck and can't see on how to add the total responses
submitted by the user.
So far I have an output which puts in a list all the user's responses, such as
responses = [{'a1': [1], 'a