A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-January/042121.html below:

[Python-Dev] dict.addlist()

[Python-Dev] dict.addlist()Barry Warsaw barry at python.org
Tue Jan 20 09:52:05 EST 2004
On Tue, 2004-01-20 at 09:26, Bob Ippolito wrote:
> On Jan 20, 2004, at 9:17 AM, Raymond Hettinger wrote:
> 
> > Here is anidea to kick around:
> >
> > Evolve and eventually replace dict.setdefault with a more specialized
> > method that is clearer, cleaner, easier to use, and faster.
> >
> >        d.addlist(k, v)   would work like   d.setdefault(k, 
> > []).append(v)
> 
> -1
> 
> There are other reasons to use setdefault.  This one is pretty common 
> though, but I think a more generic solution could be implemented.
> 
> Perhaps:
> 
> d.setdefault(k, factory=list).append(v) ?

d.setdefault(k, []).append(v)

I'm not sure what any of the other suggestions buy you except avoiding a
list instantiation, which doesn't seem like enough to warrant the extra
complexity.  I use setdefault() quite a bit (big surprise, huh?) and
occasionally would like lazy evaluation of the second argument, but it
usually doesn't bother me.

-Barry



More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4