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

Victor Stinner victor.stinner at gmail.com
Wed Sep 11 17:49:25 CEST 2013

2013/9/11 Ethan Furman <ethan at stoneleaf.us>:
> He isn't keeping the key unchanged (notice no white space in MAPPING), he's
> merely providing a function that will automatically strip the whitespace
> from key lookups.

transformdict keeps the key unchanged, see the first message:

   >>> d = transformdict(str.lower)
   >>> d['Foo'] = 5
   >>> d['foo']
   >>> d['FOO']
   >>> list(d)

'Foo' is stored as 'Foo', not as 'foo'. So for stripped keys:

d=transformdict(str.strip); d['   abc   ']; print(list(d))

should print "['   abc   ']", not "['abc']".

Is it the expected result?


More information about the Python-Dev mailing list