[Python-Dev] Proposal: defaultdict (original) (raw)
Gareth McCaughan gmccaughan at synaptics-uk.com
Wed Mar 1 14:32:39 CET 2006
- Previous message: [Python-Dev] Using and binding relative names (was Re: PEP forBetter Control of Nested Lexical Scopes)
- Next message: [Python-Dev] Stateful codecs [Was: str object going in Py3K]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>> d.get(key, [], True).append(value) > > hmm. are you sure you didn't just reinvent setdefault ?
I'm reasonably sure I copied it on purpose, only with a name that isn't 100% misleading as to what it does ;)
Heh. From the original Usenet posting that suggested the capability that was added in the form of "setdefault":
| I suggest a minor change: another optional argument to | "get" so that | | dict.get(item,default,flag) | | is equivalent to | | if dict.has_key(item): | VALUE IS dict[item] | else: | if flag: dict[item] = default <-- This is all that's new | VALUE IS default | | but presumably more efficient.
The response was a chorus of people saying "Not a bad idea, but that flag sucks. It needs a separate method." :-)
-- g
- Previous message: [Python-Dev] Using and binding relative names (was Re: PEP forBetter Control of Nested Lexical Scopes)
- Next message: [Python-Dev] Stateful codecs [Was: str object going in Py3K]
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]