User talk:WillNess: Difference between revisions

Content added Content deleted
mNo edit summary
(typos)
Line 3: Line 3:
Hi, you made an edit to [[Hamming numbers]] with the comment "according to docs for tee() storage is NOT shared among its iterators". I would like to know what you mean. What does it mean that storage is not shared. --[[Special:Contributions/208.80.119.67|208.80.119.67]] 00:49, 9 September 2011 (UTC)
Hi, you made an edit to [[Hamming numbers]] with the comment "according to docs for tee() storage is NOT shared among its iterators". I would like to know what you mean. What does it mean that storage is not shared. --[[Special:Contributions/208.80.119.67|208.80.119.67]] 00:49, 9 September 2011 (UTC)


:[http://docs.python.org/library/itertools.html#itertools.tee the docs] says it is "equivalent to":
:[http://docs.python.org/library/itertools.html#itertools.tee Documentation] says it is "equivalent to":
<lang Python>def tee(iterable, n=2):
<lang Python>def tee(iterable, n=2):
it = iter(iterable)
it = iter(iterable)
Line 16: Line 16:
return tuple(gen(d) for d in deques)
return tuple(gen(d) for d in deques)
</lang>
</lang>
:I read it to show that each iterator produced by <code>tee()</code> holds on to its own dequeue (list with pop() and append()). When a new item is needed from the original iterable, it is appended separately into each one of the dequeues. Were they all to share one dequeue amongst themselves, that would be a shared storage. <code>popleft()</code> wouldn't be always called, but only when the ''leftmost'' of internal iterators pointing into internal list would get advanced. [[User:WillNess|WillNess]] 10:53, 9 September 2011 (UTC)
:I read it to show that each generator produced by <code>tee()</code> holds on to its own dequeue (list with pop() and append()). When a new item is taken from the original iterable, it is appended separately into each one of the dequeues. Were they all to share one dequeue amongst themselves, that would be a shared storage. <code>popleft()</code> wouldn't be always called, but only when the ''leftmost'' of internal iterators pointing into internal list would get advanced. [[User:WillNess|WillNess]] 10:53, 9 September 2011 (UTC)