I know how to use the zip() function in Python 3. My question is regarding the following which I somehow feel quite peculiar:
I define two lists:
lis1 = [0, 1, 2, 3] lis2 = [4, 5, 6, 7] and I use the zip() on these in the following ways:
1. test1 = zip( lis1, lis2) 2. test2 = list(zip(lis1, lis2)) when I type test1 at the interpreter, I get this:
"zip object at 0x1007a06c8" So, I type list(test1) at the interpreter and I get the intended result, but when I type list(test1) again, I get an empty list.
What I find peculiar is that no matter how many times I type test2 at the interpreter I always get the intended result and never an empty list.
test2 = [*zip(lis1, lis2)].test2 = *zip(lis1, lis2),unpacks the zip-iterator into a tuple (Python 3).zipproduces an iterator in 3.x, as opposed to a list (as it did in 2.x). I haven't been able to find a better version of the question that focuses on only the latter part.