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
That's what setdefault() is for:
q = d.setdefault(x, {})
It does exactly what you want:
d[x]
x
d
{}