3 ms·
I like list comprehensions and to me dict comprehensions feel like a natural extension of this. It means that you can do things like {k.upper(): v ** 2 for
by aaren 13y ago
I like list comprehensions and to me dict comprehensions feel like a natural extension of this. It means that you can do things like
{k.upper(): v ** 2 for k, v in zip(keys, values)}
Or generally
{f(k): g(v) for k, v in zip(keys, values)}
I find this very extensible. In terms of conciseness, they both fit on a single line and I like the whitespace inside a dict comprehension.