Playing around with python3 REPL and noticed the following:
Why are print( [zip([1,2,3], [3,1,4])] )
and print( list(zip([1,2,3], [3,1,4])) )
different?
The first returns [<zip object at 0xblah>]
and the second returns [(1,3), (2,1), (3,4)]
.
Trying to understand why the list comprehension in the first statement doesn’t give me the result that the list()
constructor gives - I think I'm confused about the difference between list comprehension and list()
and would appreciate insight into what's happening under the hood.
Searching gives me this question on lists and tuples which doesn't answer my question.
Edit: A suggested question on The zip() function in Python 3 is very helpful background, but does not address the confusion in my question about the difference between a list comprehension and a list literal, so i prefer the submitted answer below as more complete.