Python 3.7 compatibility
See PEP 479 for the breaking changes around iterators, based on
suggestions for myitertools.py changes.
Fixes
# limitations under the License.
from itertools import cycle
+from itertools import islice
def istep(seq, step=2):
iterable = iter(seq)
while True:
- yield [next(iterable) for _ in range(step)]
+ item = list(islice(iterable, step))
+ if len(item) < step:
+ break
+ yield item
def stepslice(iterable, steps):
+ try:
iterable = iter(iterable)
step = cycle(steps)
@@ -44,3 +49,5 @@ def stepslice(iterable, steps):
# skip (2)
for _ in range(next(step)):
next(iterable)
+ except StopIteration:
+ return
