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) if __name__ == "__main__": a = range(10) print(list(ISlice(a)[5:9])) a = range(10) print(list(ISlice(a)[5])) I don't know whether I'd find it useful enough to be worth it, though... Paul _______________________________________________ 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/ZTN4ONJOG3NCDWHHPU2NEKU6YDANGQ3Z/ Code of Conduct: http://python.org/psf/codeofconduct/