I have the following snippet:
a, b = 1, 2
params = ['a', 'b']
res = {p: vars()[p] for p in params}
Which gives me KeyError: 'a'
whereas the following code works fine:
a, b = 1, 2
params = ['a', 'b']
res = {}
for p in params:
res[p] = vars()[p]
What's the difference here?