I am writing a little script in which I call itertools.product like so:
for p in product(list1,list2,list3):
self.createFile(p)
Is there a way for me to call this function without knowing in advance how many lists to include?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use the star or splat operator (it has a few names):
for p in product(*lists)wherelistsis a tuple or list of things you want to pass.You can do a similar thing when defining a function to allow it to accept a variable number of arguments:
And of course, you can combine the splat operator with the variable number of arguments: