I am new to python. I\'m trying to write this
if x not in d: d[x] = {} q = d[x]
in a more compact way using the ternary operator
The conditional operator in Python is used for expressions only, but assignments are statements. You can use
q = d.setdefault(x, {})
to get the desired effect in this case. See also the documentation of dict.setdefault().