Re:Hidden features of Python
by twism on Tuesday July 13, 2010 @08:29PM
(#1513194)
In python land (Django) for the past couple of months and I've been loving it, just thought this was a good excuse to fire up slime. In clojure...
usage:
[ Parent
| on HN ]
Pre 2.7, you can just give the dict constructor a generator of tuples:
>>> dict((s, len(s)) for s in ["one", "two", "three"])
{'three': 5, 'two': 3, 'one': 3}
Re:Hidden features of Python
by calibraxis on Wednesday July 14, 2010 @03:44AM
(#1513961)
Thank you very much! Lack of simple dict-building had been bothering me.
map-comprehension is a bad name for that function, since it doesn't give you comprehension-like syntax, instead it is just a function that behaves like map but produces a map instead of another sequence. I'd call it map-map.