On Sat, 9 May 2020 at 10:13, Ram Rachum firstname.lastname@example.org wrote:
Here's an idea I've had. How about instead of this:
itertools.islice(iterable, 7, 20)
We'll just have:
- More familiar slicing syntax.
- 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)
- 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.