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

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

[Python-Dev] Add a "transformdict" to collections [Python-Dev] Add a "transformdict" to collectionsPaul Moore p.f.moore at gmail.com
Tue Sep 10 14:24:29 CEST 2013
On 10 September 2013 13:00, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Is this just syntactic sugar for recursive lookup of a transformed version
> in __missing__? Or a way of supplying a custom "key" function to a
> dictionary?

Not quite, because the dict should preserve the originally entered key.

>>> td['FOO'] = 42
>>> td['bar'] = 1
>>> td['foo']
42
>>> td['BAR']
1
>>> list(td.keys())
['FOO', 'bar']

This actually prompts the question, what should the following produce:

>>> td['FOO'] = 42
>>> td['foo'] = 32
>>> list(td.keys())

['FOO'] or ['foo']? Both answers are justifiable. Both are possibly
even useful depending on context...

Paul
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