[Python-ideas] slice[] to get more complex slices

Todd toddrjen at gmail.com
Sun Jul 22 15:03:42 EDT 2018

For basic slices, the normal "slice(start, stop, step)" syntax works well.
But it becomes much more verbose to create more complicated slices that you
want to re-use for multiple multidimensional data structures, like numpy,
pandas, xarray, etc.

One idea I had was to allow creating slices by using indexing on the slice
class.  So for example:

    x = slice[5:1:-1, 10:20:2, 5:end]

Would be equivalent to:

    x = (slice(5, 1, -1), slice(10, 20, 2), slice(5, None))

Note that this wouldn't be done on a slice instance, it would be done on
the slice class.  The basic idea is that it would simply return whatever is
given to __getitem__.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180722/5b463d21/attachment.html>

More information about the Python-ideas mailing list