Le Tue, 10 Sep 2013 13:24:29 +0100, Paul Moore firstname.lastname@example.org a écrit :
On 10 September 2013 13:00, Nick Coghlan email@example.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']
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...
I think it would be best to leave it as an implementation detail, because whichever is easiest to implement depends on the exact implementation choices (e.g. C vs. Python).
(my prototypes right now conserve the last __setitem__ key, not the first)