File tree 1 file changed +11
-10
lines changed
1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -690,18 +690,19 @@ loops that truncate the stream.
690
690
691
691
def tee(iterable, n=2):
692
692
iterator = iter(iterable)
693
- empty_link = [None, None] # Singly linked list: [value, link ]
694
- return tuple(_tee(iterator, empty_link ) for _ in range(n))
693
+ shared_link = [None, None]
694
+ return tuple(_tee(iterator, shared_link ) for _ in range(n))
695
695
696
696
def _tee(iterator, link):
697
- while True:
698
- if link[1] is None:
699
- try:
700
- link[:] = [next(iterator), [None, None]]
701
- except StopIteration:
702
- return
703
- value, link = link
704
- yield value
697
+ try:
698
+ while True:
699
+ if link[1] is None:
700
+ link[0] = next(iterator)
701
+ link[1] = [None, None]
702
+ value, link = link
703
+ yield value
704
+ except StopIteration:
705
+ return
705
706
706
707
Once a :func: `tee ` has been created, the original *iterable * should not be
707
708
used anywhere else; otherwise, the *iterable * could get advanced without
You can’t perform that action at this time.
0 commit comments