0

So here is an example of what I have:

x1 = [1,2,3]
x2 = [4,5,6]

if I run:

x3 = zip([x1,x2])

I get: [([1,2,3],),([4,5,6])]

and if I run:

x3 = zip(x1,x2)

I get what I am looking for: [(1,4),(2,5),...]

Here is the crux of the problem:

I have a function signature that I want to define as:

def function(...):
    return [x1,x2,...],y

Where x1 and x2, ... are each lists, and the number of x's is arbitrary...

And I need to zip the output such that I have, essentially:

[(x1[0],x2[0],...,xn[0]), (x1[1],x2[1],...,xn[1]),...,(x1[n2],x2[n2],...,xn[n2])]

If I instead output a tuple from the function, the zip still fails (it zips it like a list):

def function(x1,x2):
     return (x1,x2)

x4 = zip(function(x1,x2))

output: [([1,2,3],),...]

The only thing I can think of is accumulating an argument somehow...but I have a feeling that what I am trying to do with zip might be impossible. Is there a way to pass back a list of vectors, and turn them into a list of rows with the elements being the first element of each vector? I'd really rather avoid python for loops to do this... (and is it even possible to accumulate an argument to pass to a function?)

martineau
  • 119,623
  • 25
  • 170
  • 301
Chris
  • 28,822
  • 27
  • 83
  • 158

1 Answers1

3

Same as always .

zip(*[x1,x2])
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358