Lily
Lily

Reputation: 846

Passing list names as argument to izip

I have number of lists that is user defined

numLists = sys.argv[1]
d = [[] for x in xrange(numLists+1)]

I'm performing some operations on these lists and I want to pass them at the end to itertools.izip in the following format, for example if the user entered numLists = 2

I want the line to be

  for val in itertools.izip(d[0],d[1],d[2]):
    writer.writerow(val)

Usually if I already have some predefined lists A[], B[]

The line will be

  for val in itertools.izip(A,B):
    writer.writerow(val)

Is there a way to pass the list names into izip?

NOTE:

I do not want to do this for j in range(numLists): for val in itertools.izip(d[j]): writer.writerow(val)

because it does not give the needed output.

Upvotes: 0

Views: 41

Answers (1)

alecxe
alecxe

Reputation: 473873

Unpack the list of lists into positional arguments of izip():

for val in itertools.izip(*d):

Upvotes: 2

Related Questions