I think the approach you mentioned using dict () and a list of tuples is how I did it:
dict([(x, 3) for x in [_id, _if, _while, _lbrace, _println]] + [(_variable, 2)])
If you really want to use dict comprehension, you can do something like this:
{ x : 2 if x == _variable else 3
for x in [_id, _if, _while, _lbrace, _println, _variable] }
source
share