File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change @@ -698,18 +698,19 @@ loops that truncate the stream.
698698
699699 def tee(iterable, n=2):
700700 iterator = iter(iterable)
701- empty_link = [None, None] # Singly linked list: [value, link ]
702- return tuple(_tee(iterator, empty_link ) for _ in range(n))
701+ shared_link = [None, None]
702+ return tuple(_tee(iterator, shared_link ) for _ in range(n))
703703
704704 def _tee(iterator, link):
705- while True:
706- if link[1] is None:
707- try:
708- link[:] = [next(iterator), [None, None]]
709- except StopIteration:
710- return
711- value, link = link
712- yield value
705+ try:
706+ while True:
707+ if link[1] is None:
708+ link[0] = next(iterator)
709+ link[1] = [None, None]
710+ value, link = link
711+ yield value
712+ except StopIteration:
713+ return
713714
714715 Once a :func: `tee ` has been created, the original *iterable * should not be
715716 used anywhere else; otherwise, the *iterable * could get advanced without
You can’t perform that action at this time.
0 commit comments