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

Santiago Basulto santiago.basulto at gmail.com
Wed Mar 18 22:28:23 EDT 2020


Hello community. I have an idea to share with the list to see what you all
think about it.

I happen to use both Python for Data Science (with our regular friends
NumPy and Pandas) as well as for scripting and backend development. Every
time I'm working in server-side Python (not the PyData stack), I find
myself missing A LOT features from NumPy, like fancy indexing or boolean
arrays.

So, has it ever been considered to bake into Python's builtin list and
dictionary types functionality inspired by NumPy? I think multi indexing
alone would be huge addition. A few examples:

For lists and tuples:
    >>> l = ['a', 'b', 'c']
    >>> l[[0, -1]]
    ['a', 'c']

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']]

I really like the syntax of boolean arrays too, but considering we have
list comprehensions, seems a little more difficult to sell.

I'd love to see if this is something people would support, and see if
there's room to submit a PEP.

-- 
Santiago Basulto.-
Up!


More information about the Python-list mailing list