I want to do something like this:
parsetable = {
# ...
declarations: {
token: 3 for token in [_id, _if, _while, _lbrace, _println]
}.update({_variable: 2}),
#...
}
However this doesn’t work because update doesn’t return anything. Is there any easy way to do this besides writing the entire dict explicitly?
It should be possible using dict() and a list comprehension of tuples + the extra part, but that is awkward.
I think the approach you mentioned using dict() and a list of tuples is the way I would do it:
If you really want to use a dict comprehension you can do something like this: