Preferred Python idiom for handling non-existing dictionary keys and why?
Mike Rovner
mike at nospam.com
Fri Oct 10 18:15:16 EDT 2003
Tim Peters wrote:
> [Skip Montanaro]
>> d.setdefault() never made any sense to me (IOW, to use it I always
>> had to look it up). The semantics of what it does just never stick
>> in my brain.
>
> Mentally change the name to getorset() and I bet it will be easier.
> d.getorset(x, default) gets the value of d[x] if there is one
> already, or sets d[x] to default and returns that. I think Guido
> would have changed the name to something sane, except he was pissed
> at me that day <wink>.
How to (persuade GvR to) add 'getorset' as an alias of setdefault to the
language? ;)
I also'd love to have it.
Mike
More information about the Python-list
mailing list