I'm practicing some python syntax exercises and I decided to write a dictionary comprehension based on a similarly designed list comprehension. But while the later is OK, the former results in a syntax error.
This is my list comprehension..
>>> l = [z**z if z%2 else z for z in range(5)]
[0, 1, 2, 27, 4]
and this is my dictionary comprehension..
>>> d = {z:z**z if z%2 else z:z for z in range(5)}
^
SyntaxError: invalid syntax
is there a way to write a dictionary comprehension that is similar in design to my list comprehension?