On Wed, Jun 7, 2017 at 3:11 PM, Erik <pyt...@lucidity.plus.com> wrote:
> 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) > > > Or even: from operator import itemgetter retrieve = itemgetter('a', 'b', 'c') a, b, c = retrieve(dictionary) > > $ 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. > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > -- Matt Gilson | Pattern Software Engineer getpattern.com <https://www.getpattern.com?utm_source=email&utm_medium=email&utm_campaign=signature-matt>
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/