A RetroSearch Logo

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

Search Query:

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

[Python-Dev] dict.addlist()

[Python-Dev] dict.addlist()Jeremy Hylton jeremy at alum.mit.edu
Tue Jan 20 09:46:02 EST 2004
On Tue, 2004-01-20 at 09:41, Moore, Paul wrote:
> From: Raymond Hettinger
> > [Bob Ippolito]
> >> d.setdefault(k, factory=list).append(v) ?
> >
> > That is somewhat nice and backwards compatible too.
> 
> -1
> 
> How is it more expressive than d.setdefault(k, []).append(v)? As
> far as I can see, it's longer and contains an extra obscure(ish)
> term (factory).

One benefit is that it doesn't create an unnecessary empty list when the
key is already in the dictionary.

> And I agree with the other posters that other defaults are often
> useful, and further complicating the dictionary interface isn't
> particularly helpful.
> 
> If conciseness is important,
> 
>     def addlist(d, k, v):
>         d.setdefault(k, []).append(v)

Nonetheless, I agree that the dict API is already quite large and the
benefit of this new/changed method is very small.

Jeremy



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