Re: dict.update

2008-09-02 Thread Tino Wildenhain
Mike P wrote: Hi All, I have two dictionaries e.g dict1 = {123:3,234:5,456:3} dict2 = {123:4,157:2,234:5,456:3,567:2} I want to merge these two dictionaries together so i have a resultant dictionary of: dict3 = {123:[4,3],157:[2,0],234:[5,5],456:[3,3],567:[2,0]} As later on i want to write a

Re: dict.update

2008-09-02 Thread Mike P
Thanks Raymond, That's a neat trick, i'll look into learning more about this Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: dict.update

2008-09-02 Thread Mike P
Thanks Diez, This is almost perfect! Is there a way to ensure each list has two elements, even if one of them is blank? Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: dict.update

2008-09-02 Thread Raymond Hettinger
On Sep 2, 8:04 am, Mike P <[EMAIL PROTECTED]> wrote: > Hi All, > > I have two dictionaries e.g > dict1 = {123:3,234:5,456:3} > dict2 = {123:4,157:2,234:5,456:3,567:2} > > I want to merge these two dictionaries together so i have a resultant > dictionary of: > > dict3 = {123:[4,3],157:[2,0],234:[5,5

Re: dict.update

2008-09-02 Thread Diez B. Roggisch
Mike P schrieb: Hi All, I have two dictionaries e.g dict1 = {123:3,234:5,456:3} dict2 = {123:4,157:2,234:5,456:3,567:2} I want to merge these two dictionaries together so i have a resultant dictionary of: dict3 = {123:[4,3],157:[2,0],234:[5,5],456:[3,3],567:[2,0]} As later on i want to write

Re: dict.update() useful or not?

2008-08-13 Thread Aahz
In article <[EMAIL PROTECTED]>, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > >What do other people find? Do you find use for dict.update()? What other >idioms do you use for combining dictionaries? My company's code relies heavily on d.update() -- it's extremely handy in the context of a web for

Re: dict.update() useful or not?

2008-08-11 Thread Martin v. Löwis
>> def create_request(url, headers): >> headers.update(DEFAULT_HEADERS) >> req = urllib2.Request(url, None, headers) >> # ... >> return req >> >> but of course this second example does the Wrong Thing, replacing >> explicit headers with default values. > > There's a second code s

Re: dict.update() useful or not?

2008-08-11 Thread Duncan Booth
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > dict1.update(dict2) is of course equivalent to this code: > > for key, value in dict2.iteritems(): > dict1[key] = value > > Note that it replaces values in dict1 with the value taken from dict2. I > don't know about other people, but I more often