Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 1
    From the documentation of itertools.tee: "This itertool may require significant auxiliary storage (depending on how much temporary data needs to be stored). In general, if one iterator uses most or all of the data before another iterator starts, it is faster to use list() instead of tee()."
    – Matthias
    Commented Mar 30, 2020 at 17:06
  • 1
    Maybe this is just to set the question up, but why are you calling iter in the first place, instead of using fruit directly? The for loop is implicitly calling iter on its, even if it is already an iterator.
    – chepner
    Commented Mar 30, 2020 at 17:13
  • @chepner, I don't have control over iter but from the structure of the code, that is what is happening. I am to just consume the iterator. Commented Mar 30, 2020 at 17:18
  • As an aside, why del it1, it2? It's pointless. Anyway, tee is good of you use part of the results then need to start consuming again, if you are going to consume the whole thing once then need to do it again, you might as well just use list Commented Mar 30, 2020 at 19:13