Since you're using Python for your example, it's worth mentioning that 3.5 extended the unpacking syntax [1] to sort of do what you want.
foo = {
'a': 1,
'b': 2,
**({
'c': 3,
'd': 4,
} if bar else {}),
}
This adds `c: 3` and `d: 4` into `foo` conditional on `bar`.[1] https://docs.python.org/3/whatsnew/3.5.html#pep-448-addition...