[Python-ideas] Remapping a table's keys
Ben Finney
ben+python at benfinney.id.au
Fri Nov 5 03:10:41 CET 2010
Chris Rebert <pyideas at rebertia.com> writes:
> # Requires Python 2.7+ (dict comprehension)
> ret = {key_map.get(k, k) : v for k,v in dict_from_elsewhere.items()}
If using a Python without dict comprehensions but with generator
expressions::
ret = dict(
(key_map.get(k, k), v)
for (k, v) in dict_from_elsewhere.items())
--
\ “Pinky, are you pondering what I'm pondering?” “Well, I think |
`\ so, Brain, but do I really need two tongues?” —_Pinky and The |
_o__) Brain_ |
Ben Finney
More information about the Python-ideas
mailing list