Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. >>> list(itertools.tee('ABC'))
  2. [<itertools._tee object at 0x109cebe88>, <itertools._tee object at 0x109cf3048>]
  3. >>> g1, g2 = itertools.tee('ABC')
  4. >>> g1
  5. <itertools._tee object at 0x109cf3108>
  6. >>> next(g1)
  7. 'A'
  8. >>> next(g2)
  9. 'A'
  10. >>> next(g2)
  11. 'B'
  12. >>> next(g2)
  13. 'C'
  14. >>> next(g2)
  15. Traceback (most recent call last):
  16. File "<stdin>", line 1, in <module>
  17. StopIteration
  18. >>> list(g1)
  19. ['B', 'C']
  20. >>> list(g2)
  21. []
  22. >>> list(zip(*itertools.tee('ABC')))
  23. [('A', 'A'), ('B', 'B'), ('C', 'C')]
  24. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement