[Python-Dev] PEP 455: TransformDict (original) (raw)
Antoine Pitrou solipsis at pitrou.net
Sat Sep 14 03:02:52 CEST 2013
- Previous message: [Python-Dev] PEP 455: TransformDict
- Next message: [Python-Dev] PEP 455: TransformDict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, 14 Sep 2013 10:49:52 +1000 Steven D'Aprano <steve at pearwood.info> wrote:
Is it more common to want both the canonical key and value at the same time, or to just want the canonical key? My gut feeling is that I'm likely to have code like this: d = TransformDict(...) for key in data: key = d.getcanonical(key) value = d[key] print("{}: {}".format(key, value)) in which case having a single call to return both will be great: for key in data: key, value = d.getitem(key) print("{}: {}".format(key, value)) but I'm really not sure. Maybe Ethan is right.
I don't think it really matters. From getitem() it's trivial to extract the key alone.
I think these sorts of associated questions are why some people (Raymond, Nick) want to see the proposal live outside of the standard library for a while first. The general idea is great, but we're going to bike shed the API without having much idea of how it will actually be used.
Even after it's used, it will still be bikeshedded: such is how proposals are generally discussed. There really isn't very much to decide here, and whether we only return a key or a (key, value) pair is almost cosmetic: both APIs are reasonably convenient.
So, my suggestion is this:
- Let's add transform to dicts for 3.4, similar to missing, and see how people end up using it in the real world.
Well, missing isn't used very much, I think. People use defaultdict. (note that I'm not even proposing transform right now :-))
+1 on transform method on dicts.
+0 on TransformedDict in 3.4 +1 on waiting for 3.5 based on experience on using transform.
Ok, thanks.
Regards
Antoine.
- Previous message: [Python-Dev] PEP 455: TransformDict
- Next message: [Python-Dev] PEP 455: TransformDict
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]