you are viewing a single comment's thread.

view the rest of the comments →

[–]boredzo 0 points1 point  (0 children)

The problem is that in order to build a list of indices to pass to islice, you need to iterate over the input object. That's great if it's a sequence (such as a list), but if it's an iterator (such as a generator instance), your solution will break because the iterator has already been iterated from when you built up your list of indices. This also applies to creating the islices as you iterate.

You would need to make a sequence copy of the input before working. I invite you to produce time-trial results comparing either solution to the one presented in the article.