Issue
I created two lists in python 3.7.1, and zipped them using zip
.
When I tried printing the result to the console, it worked the first time, but gave an empty list afterwards:
Why i am able to retrieve the values only once?
Solution
The zip function is actually just an iterator -- an iterator can only be traversed once. If you want to be able to iterate over it multiple times, convert it to a list first.
a = [1,2,3]
b = [1,2,3]
c = list(zip(a, b))
Answered By - Russell Cohen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.