by bjourne · 4y ago · 0 comments
d = {'a' : 10, 'b' : 20, 'c' : 30}
{'a' : v1, 'b' : v2, **others} = d
print(v1, v2, others) # prints 10, 20, {'c' : 30}The working code in Python, as a function, would be:
def extract(mapping, *args, **kwargs):
for a in args:
yield mapping[a]
for key, default in kwargs.items():
yield mapping.get(key, default)