3 ms·
I'd disagree, as dict(zip(keys, value)) is more concise, doesn't introduce extra variables, and doesn't repeat itself, and explicitly names a dict rather th
by epistasis 13y ago
I'd disagree, as
dict(zip(keys, value))
is more concise, doesn't introduce extra variables, and doesn't repeat itself, and explicitly names a dict rather than using a symbol.
- herge 13y agoRight, but the second you need to modify either the key or the value, you are better off with the dict comprehension. It's like map() vs [...].
- aaren 13y agoI 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.