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

2013年9月11日 15:43:24 -0700

On 09/11/2013 02:39 PM, Tim Delaney wrote:
On 12 September 2013 02:03, Ethan Furman <[email protected] 
<mailto:[email protected]>> wrote:
 On 09/11/2013 08:49 AM, Victor Stinner wrote:
 2013年9月11日 Ethan Furman <[email protected] <mailto:[email protected]>>:
 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']
 5
 >>> d['FOO']
 5
 >>> list(d)
 ['Foo']
That seems backwards to me. I would think that retrieving the keys from the 
dict would return the transformed keys (I'd
call them canonical keys). That way there's no question about which key is 
stored - it's *always* the transformed key.
At this point there is still no question: it's the first version of the key 
seen. For a stupid example:
--> d = transformdict(str.lower)
--> d['ThePyramid'] = 'Game Show'
--> d['AtOnce'] = now()
--> for k, v in d.items():
... print(k, v)
Imagine writing a function to get that capitalization right.
In fact, I think this might get more traction if it were referred to as a 
canonicalising dictionary (bikeshedding, I know).
Whoa, that's way harder to spell! ;) Drop the 'ising', though, and I'm in.
--
~Ethan~
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to