On Sat, 9 May 2020 at 10:13, Ram Rachum <r...@rachum.com> wrote: > > Here's an idea I've had. How about instead of this: > > itertools.islice(iterable, 7, 20) > > We'll just have: > > itertools.islice(iterable)[7:20] > > > Advantages: > 1. More familiar slicing syntax. > 2. No need to awkwardly use None when you're interested in just specifying > the end of the slice without specifying the start, i.e. islic(x)[:10] instead > of islice(x, None, 10) > 3. Doesn't require breaking backwards compatibility. > > > What do you think?
Why would you use islice(x, None, 10)? islice(x, 10) does the same... I guess you might occasionally do islice(x, None, end, step), but that seems fairly rare. The proposed syntax looks cute, but I'm not sure it's an improvement. And you have to consider what happens when people start passing islice(x) objects around *without* immediately indexing them. You now have objects that (presumably) support slice indexing, but not indexing with an integer, and not len(). Those are bound to end up somewhere they shouldn't and break someone's assumptions... These objections aren't showstoppers, but IMO they do far outweigh the relatively trivial benefits. 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/ICUQFHL5P5JI7XATKLCI3VFSAP325VIV/ Code of Conduct: http://python.org/psf/codeofconduct/