3

When I try to execute this code

g = [1, 2, 3, 4, 5, 6]
zip(*g)

I get the following error

zip argument #1 must support iteration

I am trying to convert row into column vector

I even tried map(list, zip(*gate)) still I get the same error

Please help

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
SIMHA
  • 161
  • 1
  • 1
  • 3

1 Answers1

6

With zip(*g) syntax, you are doing list unpacking. The following code:

g = [1, 2, 3, 4, 5, 6]
zip(*g)

Is equivalent to:

zip(1, 2, 3, 4, 5, 6)

Since g list contains int values (but not iterable collection) you get an error.

notice: the zip function can have a variable list of parameters.

So, to fix your problem you need to write:

zip(g)

Remember that, in Python 3, zip return a generator. To get a list you need to use the list function:

>>> list(zip([1, 2, 3, 4, 5, 6]))
[(1,), (2,), (3,), (4,), (5,), (6,)]
Laurent LAPORTE
  • 21,958
  • 6
  • 58
  • 103