We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d368747 commit 2c5150cCopy full SHA for 2c5150c
unpythonic/it.py
@@ -688,13 +688,13 @@ def chunked(n, iterable):
688
raise ValueError("expected n >= 2, got {}".format(n))
689
it = iter(iterable)
690
def chunker():
691
- while True:
692
- chunk_it = islice(it, n)
693
- try:
694
- first_el = next(chunk_it)
695
- except StopIteration:
696
- return
697
- yield scons(first_el, chunk_it)
+ try:
+ while True:
+ cit = islice(it, n)
+ # we need the next() to see the StopIteration when the first empty slice occurs
+ yield scons(next(cit), cit)
+ except StopIteration:
+ return
698
return chunker()
699
700
def within(tol, iterable):
0 commit comments