Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'zip' object is not callable in Python 3.x

I'm trying to zip 2 simple lists in Python 3.5, and can't figure out how to access the contents. I've read now that zip() is a generator, and I have to call list(zip()) if I want to store the contents. However, I'm experiencing an error when doing so.

For example:

row = [1, 2, 3]
col = ['A', 'B', 'C']
z = zip(row, col)

When I call 'z', I see the following:

>>> z
<zip object at 0x0283C8F0>

But when I call list(z), I get the following error:

>>> list(z)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'zip' object is not callable

I also get the same error when attempting to assign the list to a variable, such as:

l = list(zip(row, col))

Apologies if this has already been answered, but I cannot for the life of me find a solution via search. Any ideas would be greatly appreciated!!

like image 892
Aaron Warnecke Avatar asked Nov 30 '17 21:11

Aaron Warnecke


1 Answers

that happens when you redefine list as zip() (which is probably what you did but didn't show us):

>>> list = zip()

now list is a zip object (not the zip class)

>>> list(z)

now you're attempting to call a zip object

Traceback (most recent call last):
  File "<string>", line 301, in runcode
  File "<interactive input>", line 1, in <module>
TypeError: 'zip' object is not callable
>>> 

just

del list

(or start from a fresh interpreter)

and everything's back to normal

like image 88
Jean-François Fabre Avatar answered Sep 22 '22 16:09

Jean-François Fabre