[Python-ideas] Dictionary destructing and unpacking.

Erik python at lucidity.plus.com
Wed Jun 7 18:11:20 EDT 2017


On 07/06/17 19:14, Nick Humrich wrote:
> a, b, c = mydict.unpack('a', 'b', 'c')

def retrieve(mapping, *keys):
    return (mapping[key] for key in keys)



$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
 >>> def retrieve(mapping, *keys):
...     return (mapping[key] for key in keys)
...
 >>> d = {'a': 1, 'b': None, 100: 'Foo' }
 >>> a, b, c = retrieve(d, 'a', 'b', 100)
 >>> a, b, c
(1, None, 'Foo')


E.


More information about the Python-ideas mailing list