python - TypeError: zip argument #1 must support iteration

python – TypeError: zip argument #1 must support iteration

python – TypeError: zip argument #1 must support iteration

I take it your code is giving you the error message, TypeError: zip argument #1 must support iteration. You are getting this error due to the expression zip(float(price), Bids). This simplified code demonstrates the error:

>>> price = str(u12.3456)
>>> bids = [1.0, 2.0]
>>> zip(float(price), bids)
Traceback (most recent call last):
  File <stdin>, line 1, in <module>
TypeError: zip argument #1 must support iteration

The Python 2.x zip() built-in library function requires all its arguments to be iterables. float(price) is not an iterable.

If you want to make tuples combining float(price) with each element of the array Bids, you can use itertools.repeat() in the first argument expression.

>>> import itertools
>>> price = str(u12.3456)
>>> bids = [1.0, 2.0]
>>> zip(itertools.repeat(float(price),len(bids)), bids)
[(12.345599999999999, 1.0), (12.345599999999999, 2.0)]

I dont see that your use of Unicode data types has anything to do with the TypeError.

python – TypeError: zip argument #1 must support iteration

Related posts on python :

Leave a Reply

Your email address will not be published.