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/2006-February/061505.html below:

[Python-Dev] defaultdict proposal round three

[Python-Dev] defaultdict proposal round three [Python-Dev] defaultdict proposal round threeSteven Bethard steven.bethard at gmail.com
Mon Feb 20 20:24:09 CET 2006
Guido van Rossum wrote:
> Alternative A: add a new method to the dict type with the semantics of
> __getattr__ from the last proposal, using default_factory if not None
> (except on_missing is inlined).

I'm not certain I understood this right but (after
s/__getattr__/__getitem__) this seems to suggest that for keeping a
dict of counts the code wouldn't really improve much:

dd = {}
dd.default_factory = int
for item in items:
    # I want to do ``dd[item] += 1`` but with a regular method instead
    # of __getitem__, this is not possible
    dd[item] = dd.somenewmethod(item) + 1

I don't think that's much better than just calling ``dd.get(item,
0)``.  Did I misunderstand Alternative A?

> Alternative B: provide a dict subclass that implements the __getattr__
> semantics from the last proposal.

If I didn't misinterpret Alternative A, I'd definitely prefer
Alternative B.  A dict of counts is by far my most common use case...

STeVe
--
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy
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