For unpacking, it made no sense to depend on variable names. The closest you can get is:
a, b = [f()[k] for k in ('a', 'b')]
This, of course, is rated twice f().
You can write a function:
def unpack(d, *keys)
return tuple(d[k] for k in keys)
Then do:
a, b = unpack(f(), 'a', 'b')
It really is all crowded. Something simple would be better:
result = f()
a, b = result['a'], result['b']
source
share