The snippets
xi = xrange(10)
zip(xi,xi)
and
xi = iter(range(10))
zip(xi,xi)
behave differently. I expected to get
[(0, 1), (2, 3), (4, 5), (6, 7), (8, 9)]
in the first snippet as well, but it returns
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)]
instead. It seems the implicit container is being silently copied. Could anyone explain whats going on here ? and reasoning behind choosing such semantics.
>>> sys.version
'2.7.9 (default, Dec 10 2014, 12:28:03) [MSC v.1500 64 bit (AMD64)]'