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(u'12.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(u'12.3456')
>>> bids = ['1.0', '2.0']
>>> zip(itertools.repeat(float(price),len(bids)), bids)
[(12.345599999999999, '1.0'), (12.345599999999999, '2.0')]

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

Leave a Comment