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
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
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
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).
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
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?
>>>
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
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
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
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
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)
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
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)
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
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
15 matches
Mail list logo