Re: Why dict.setdefault() has value as optional?

2022-02-02 Thread Marco Sulla
On Wed, 2 Feb 2022 at 14:34, Lars Liedtke wrote: > > This is a quite philosophical queston if you look at it in general: > "What value do you give a variable, that is not set?" Maybe I expressed my question badly. My existential doubt is why setdefault has an optional parameter for the value and

Re: Why dict.setdefault() has value as optional?

2022-02-02 Thread Lars Liedtke
t that can have multiple keys with each different values of different types? Have fun in the rabbithole ;-) Cheers Lars Am 02.02.22 um 13:54 schrieb Marco Sulla: Just out of curiosity: why dict.setdefault() has the default parameter that well, has a default value (None)? I used setdefault i

Why dict.setdefault() has value as optional?

2022-02-02 Thread Marco Sulla
Just out of curiosity: why dict.setdefault() has the default parameter that well, has a default value (None)? I used setdefault in the past, but I always specified a value. What's the use case of setting None by default? -- https://mail.python.org/mailman/listinfo/python-list

Re: dict.setdefault()

2011-04-25 Thread Thomas Rachel
Am 12.04.2011 04:58, schrieb rantingrick: That's sounds good MRAB! After you mentioned this i had an epiphany... why not just add an extra argument to dict.update? dict.update(D, clobberexistingkeys=False) This is AFAICS inconsistent to the possibility to do dict.update(a, k1=v1, k2=v2).

Re: dict.setdefault()

2011-04-12 Thread Westley Martínez
On Mon, 2011-04-11 at 19:58 -0700, rantingrick wrote: > > > >>> dict.update(D, cobblerexistingkeys=False) Fix'd Much yummier now. -- http://mail.python.org/mailman/listinfo/python-list

Re: dict.setdefault()

2011-04-11 Thread rantingrick
On Apr 11, 5:41 pm, MRAB wrote: > A new method like "updatedefault" may be better, IMHO. It would act > like "update" except that it wouldn't overwrite existing values. That's sounds good MRAB! After you mentioned this i had an epiphany... why not just add an extra argument to dict.update? >>>

Re: dict.setdefault()

2011-04-11 Thread Raymond Hettinger
On Apr 11, 4:25 pm, Tim Chase wrote: > Finally, if it were added, I'd call it something like merge() Guido rejected merge() a long time ago. Anyway, there is a new ChainMap() tool in the collections module for Py3.3 that should address a number of use cases for handling default values. Raymond

Re: [Feature Request] dict.setdefault()

2011-04-11 Thread Tim Chase
self[k] = v def updatedefault(self, d={}, **kwargs): for k,v in chain( dict(d).iteritems(), kwargs.iteritems() ): # MRAB's comment about "wouldn't overwrite existing" if k not in self: self[k] = v My concern with the initial request is t

Re: [Feature Request] dict.setdefault()

2011-04-11 Thread MRAB
On 11/04/2011 23:44, Chris Angelico wrote: On Tue, Apr 12, 2011 at 8:41 AM, MRAB wrote: I'm not sure that "setdefault" should take **kw args for this because of its existing argument structure (key + optional value). A new method like "updatedefault" may be better, IMHO. It would act like "upd

Re: [Feature Request] dict.setdefault()

2011-04-11 Thread Chris Rebert
On Mon, Apr 11, 2011 at 2:35 PM, rantingrick wrote: > > setdefault should take **kw args in the case of needing to set > multiple defaults at one time. I would even settle for an *arg list if > i had to. What would the return value be? dict.setdefault() doesn't currently jus

Re: dict.setdefault()

2011-04-11 Thread Raymond Hettinger
On Apr 11, 2:35 pm, rantingrick wrote: > setdefault should take **kw args in the case of needing to set > multiple defaults at one time. I would even settle for an *arg list if > i had to. Anything is better than... > > d.setdefault(blah, blah) > d.setdefault(blah, blah) > d.setdefault(blah, blah)

Re: [Feature Request] dict.setdefault()

2011-04-11 Thread Chris Angelico
On Tue, Apr 12, 2011 at 8:41 AM, MRAB wrote: > I'm not sure that "setdefault" should take **kw args for this because > of its existing argument structure (key + optional value). > > A new method like "updatedefault" may be better, IMHO. It would act > like "update" except that it wouldn't overwrit

Re: [Feature Request] dict.setdefault()

2011-04-11 Thread MRAB
On 11/04/2011 23:16, Westley Martínez wrote: On Mon, 2011-04-11 at 14:35 -0700, rantingrick wrote: setdefault should take **kw args in the case of needing to set multiple defaults at one time. I would even settle for an *arg list if i had to. Anything is better than... d.setdefault(blah, blah)

Re: [Feature Request] dict.setdefault()

2011-04-11 Thread Westley Martínez
On Mon, 2011-04-11 at 14:35 -0700, rantingrick wrote: > setdefault should take **kw args in the case of needing to set > multiple defaults at one time. I would even settle for an *arg list if > i had to. Anything is better than... > > d.setdefault(blah, blah) > d.setdefault(blah, blah) > d.setdefa

[Feature Request] dict.setdefault()

2011-04-11 Thread rantingrick
setdefault should take **kw args in the case of needing to set multiple defaults at one time. I would even settle for an *arg list if i had to. Anything is better than... d.setdefault(blah, blah) d.setdefault(blah, blah) d.setdefault(blah, blah) d.setdefault(blah, blah) if blah is not blah: d