PEP Idea: Multi-get for lists/tuples and dictionaries (inspired in NumPy)

David Raymond David.Raymond at tomtom.com
Thu Mar 19 11:50:34 EDT 2020


For dictionaries it'd even be more useful:
    d = {
        'first_name': 'Frances',
        'last_name': 'Allen',
        'email': 'fallen at ibm.com'
    }
    fname, lname = d[['first_name', 'last_name']]

Why not do this?

import operator
first_last = operator.itemgetter("first_name", "last_name")

fname, lname = first_last(d)


https://docs.python.org/3.8/library/operator.html#operator.itemgetter



More information about the Python-list mailing list