newbie dictionary question

Wolfgang Grafen wolfgang.grafen at gmx.de
Sun Apr 21 19:02:49 EDT 2002


"James Chapman <" schrieb:

> Hi,
>
> I have a question about dictionaries. I've been coding up a system of
> objects that represents the reuslts of different auctions. One thing I've
> been doing constantly though is iterating over dictionaries where the keys
> are the prices of the bids and the values are the bids at that amount.
>
> I was wondering if there is an easy way to consolidate to dictionaries into
> one, where if they both have the same key the resulting value can be
> concatenated.
>
> Also is there any similar syntax for dictionaries like the list syntax
> "[some_function(x) for x in other_list]"?
>
> Thanks,
>
> James Chapman

>>> d1={'a':1,'b':2}
>>> d2={'c':3,'b':4}
>>> d1.update(d2)
>>> d1
{'b': 4, 'c': 3, 'a': 1}

Hope this is what you mean but consider that the value of 'b' in d1 will be
overridden by the value of 'b' in d2.

wolfgang




More information about the Python-list mailing list