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/2013-September/128653.html below:

[Python-Dev] PEP 455: TransformDict

[Python-Dev] PEP 455: TransformDictSteven D'Aprano steve at pearwood.info
Sat Sep 14 05:33:51 CEST 2013
On Fri, Sep 13, 2013 at 06:40:06PM -0700, Ethan Furman wrote:

> >and if you wanted the transformed key you would apply the transform
> >function to the key.
> 
> Indeed.  The question is:  how?  It is entirely possible that your function 
> has a TransformDict alone, and no memory of the transform function used to 
> create the dict...
> 
> If the key transform function were saved directly on the TransformDict 
> instance as, say, .transform_key, then problem solved.

While I think it is good and proper to have the transformation function 
available, if you're manually applying the transformation function then 
IMO chances are good that you've missed the whole point of the 
transformdict.

Think of defaultdict. The purpose of defaultdict is to avoid needing to 
check whether the key is missing or not. If I suggested that the way 
to use a defaultdict was to write code like this:

value = d[key] if key in d else d.default_factory()

I'd be missing the point. Likewise, the point of transformdict is to 
avoid needing to care about the transformation function 99% of the 
time.



-- 
Steven
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