3 ms·
That's packing. Unpacking would be something like this: d = {'a' : 10, 'b' : 20, 'c' : 30} {'a' : v1, 'b' : v2, **others} = d print(v1, v2, others)
by bjourne 5y ago
That's packing. Unpacking would be something like this:
d = {'a' : 10, 'b' : 20, 'c' : 30}
{'a' : v1, 'b' : v2, **others} = d
print(v1, v2, others) # prints 10, 20, {'c' : 30}
- BiteCode_dev 5y agoExactly. 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)