I would like to do something like this
def f():
return { \'a\' : 1, \'b\' : 2, \'c\' : 3 }
{ a, b } = f() # or { \'a\', \'b\' } = f() ?
<
It wouldn't make any sense for unpacking to depend on the variable names. The closest you can get is:
a, b = [f()[k] for k in ('a', 'b')]
This, of course, evaluates f()
twice.
You could write a function:
def unpack(d, *keys)
return tuple(d[k] for k in keys)
Then do:
a, b = unpack(f(), 'a', 'b')
This is really all overkill though. Something simple would be better:
result = f()
a, b = result['a'], result['b']