[Python-ideas] List indexing multiple elements

Ryan Birmingham rainventions at gmail.com
Mon Feb 20 16:04:28 EST 2017

So, to make sure I have this right: your proposal says array should be
indexable by a list of indexes as they're currently done, in a tuple,
right? Would this also mean that something like (1:4, 8:10, 13) should be
an acceptable constructor for a tuple?

-Ryan Birmingham

On 20 February 2017 at 15:54, Ryan Gonzalez <rymg19 at gmail.com> wrote:

> Apologies if this has already been covered!
> Right now, if you want to get multiple elements in a list, you have to do:
> elements = [mylist[a], mylist[b]]
> My proposal is two-folded:
> - Right now, a[b,c] is already valid syntax, since it's just indexing a
> with the tuple (b, c). The proposal is to make this a specialization in the
> grammar, and also allow stuff like a[b:c, d:e] (like
> `a.__getitem__(slice(b, c), slice(d, e))`).
> - Add support for indexing via tuples in list.__getitem__.
> list.__getitem__(tuple) would roughly be equivalent to
> map(list.__getitem__, tuple).
> The first part is solely so that slices would be allowed in the syntax,
> but if you guys don't like the idea, the second part still stands.
> Thoughts? *ducks from flying tomatoes*
> --
> Ryan (ライアン)
> Yoko Shimomura > ryo (supercell/EGOIST) > Hiroyuki Sawano >> everyone else
> http://refi64.com
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170220/f6681c0b/attachment.html>

More information about the Python-ideas mailing list