[Python-Dev] PEP 455: TransformDict (original) (raw)
Joao S. O. Bueno jsbueno at python.org.br
Fri Sep 13 21:54:01 CEST 2013
- Previous message: [Python-Dev] PEP 455: TransformDict
- Next message: [Python-Dev] PEP 455: TransformDict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I see the PEP does not contemplate a way to retrieve the original key
- like we've talked about somewhere along the thread.
On 13 September 2013 16:37, Antoine Pitrou <solipsis at pitrou.net> wrote:
On Fri, 13 Sep 2013 22:31:02 +0300 Serhiy Storchaka <storchaka at gmail.com> wrote:
13.09.13 21:40, Antoine Pitrou написав(ла): > Both are instances of a more general pattern, where a given > transformation function is applied to keys when looking them up: that > function being
str.lower
in the former example and the built-in >id
function in the latter.Please use str.casefold in examples. > >>> d = TransformDict(str.lower, [('Foo': 1)], Bar=2) {'Foo': 1} or [('Foo', 1)]. Ok, thanks. > Providing a specialized container, not generic > ---------------------------------------------- > > It was asked why we would provide the generic TransformDict construct > rather than a specialized case-insensitive dict variant. The answer > is that it's nearly as cheap (code-wise and performance-wise) to provide > the generic construct, and it can fill more use cases. Except lightweight IdentityDict which can be implemented more efficient than TransformDict(id). It doesn't need in calling the transform function, computing the hash of transformed key, comparing keys. But perhaps in many cases TransformDict(id) is enough. That's true. But it's only important if TransformDict is the bottleneck. I doubt the memoizing dictionary is a bottleneck in e.g. the pure Python implementation of pickle or json. > Python's own pickle module uses identity lookups for object > memoization: > http://hg.python.org/cpython/file/0e70bf1f32a3/Lib/pickle.py#l234 Also copy, json, cProfile, doctest and threadinglocal. Thanks, will add them. Regards Antoine.
Python-Dev mailing list Python-Dev at python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/jsbueno%40python.org.br
- Previous message: [Python-Dev] PEP 455: TransformDict
- Next message: [Python-Dev] PEP 455: TransformDict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]