Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you dynamically create the arguments for the zip() function in python 2?

Tags:

zip

python-2.7

I am passing in a variable number of lists in *args to a function. What I'd like to accomplish is to pass this args to zip().

def amv(db, *args):
    x = zip(args)
    return x

I would like to avoid the following:

if len(args) == 1:
    x = zip(args[1])
elif len(args) == 2:
    x = zip(args[1], args[2])
...etc.
like image 650
Fraser Gorrie Avatar asked Aug 23 '13 16:08

Fraser Gorrie


1 Answers

Erm... you almost have it.

x = zip(*args)
like image 60
Ignacio Vazquez-Abrams Avatar answered Jan 02 '23 13:01

Ignacio Vazquez-Abrams