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/128556.html below:

[Python-Dev] Add a "transformdict" to collections

[Python-Dev] Add a "transformdict" to collections [Python-Dev] Add a "transformdict" to collectionsSerhiy Storchaka storchaka at gmail.com
Wed Sep 11 11:38:13 CEST 2013
There is a question about specifying the transform function.

There are three ways to do this:

1. Positional argument of the constructor.

d = TransformDict(str.casefold, Foo=5)

2. Subclassing.

class CaseInsensitiveDict(TransformDict):
     def transform(self, key):
         return key.casefold()
d = CaseInsensitiveDict(Foo=5)

3. Type generator.

d = TransformDict(str.casefold)(Foo=5)

Second method looks a little simpler to me from implementation side 
(What if you call __init__ for already initialized object? What if you 
used the object before calling __init__?).

Third method allows you to customize other aspects of dict behavior 
(combine OrderedDict, defaultdict,..).

First method looks less cumbersome from user side at first look. But how 
many different transform functions you use? Aren't they deserve named 
classes?


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