On Tue, 17 Nov 2020 at 22:35, Paul Moore <p.f.mo...@gmail.com> wrote:
>
> On Tue, 17 Nov 2020 at 22:19, Oscar Benjamin <oscar.j.benja...@gmail.com> 
> wrote:
> > It would be nice if islice gave an object that supported slicing so
> > that you could spell it like:
> >
> >    for x in islice(a)[5:]:
> >
> > I find it hard to decipher the meaning of the arguments to islice
> > compared to reading a normal slice expression.
>
> It's possible to write this yourself:
>
> from itertools import islice
>
> class ISlice:
>     def __init__(self, it):
>         self.it = iter(it)
>     def __getitem__(self, s):
>         if isinstance(s, slice):
>             return islice(self.it, s.start, s.stop, s.step)
>         # Presumably an integer
>         return islice(self.it, s, s+1)

I can write many things myself. That doesn't mean that it wouldn't be
good if someone already wrote it for me (and for everyone else).

In this case the islice function has already been written but it seems
to have missed a trick by not using Python's compact slice notation.

--
Oscar
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/JMB4LYL6VZSXLRDTGN4A5CISALJU6BMS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to