Reputation: 13
When I ran a code in IPython QTConsole :
-->zip([2,4],[3,1])
I expected it to output [[2,3],[4,1]], but instead it shows
-->
, something like storing address. How can I resolve this?
Upvotes: 1
Views: 22
Reputation: 8557
The reason is that zip
doesn't always get sequences as arguments. Sequences have a known order, and can be iterated over as many times as you want. Sometimes zip can get generators, where you actually don't know the order, or even how many items are in it up front.
in your specific case, you can do
list(zip([2,4],[3,1]))
To get what you want. If you're only going to iterate over the zipped thing once, you shouldn't call list
on it, because then you've done a lot of unnecessary work. It's more efficient to just iterate over the zipped thing.
Upvotes: 2