Dictionary-Comprehensions (A)

9.3.2. Dictionary-Comprehensions (A)#

Sehr ähnlich lässt sich diese Schreibweise für Wörterbücher einsetzten.

x = {'a': 1, 'b': 2, 'c': 3}

{key:v**3 for (key, v) in x.items()}
{'a': 1, 'b': 8, 'c': 27}