On Fri, 13 Sep 2013 21:59:11 -0700
Ethan Furman <[email protected]> wrote:
>
> > I mean - given no function to retrieve the canonical key,
> > one would have to resort to:
> >
> > my_key = data.__transform__(given_key)
> > for key, value in data.items():
> > if data.__transform__(key) == my_key:
> > ....
>
> Which is exactly why I, and others, would like to have the transform function
> easily available. Besides being able to
> use it to get a canonical key, one could use it to get the function itself.
> Yay, introspection!
Well, no, you misunderstand :) The transform function takes an
original key (perhaps "canonical") and returns the transformed key, it
can't do the reverse which is what getitem() does. i.e.:
>>> d = TransformDict(str.lower)
>>> d['Foo'] = 5
>>> d._transform_func('Foo')
'foo'
>>> d.getitem('foo')
[('Foo', 5)]
What getitem() does is make the surjection bijective by restricting its
input domain to the set of stored keys.
Regards
Antoine.
_______________________________________________
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