Some functions take in their parameters a variable number of arguments *args, for example, the itertools.product function.
1 2 3 |
list(itertools.product(['a', 'b'], [1, 2])) # [('a', 1), ('a', 2), ('b', 1), ('b', 2)] |
In order to pass the list as the parameters to this function, we need to use the * operator:
1 2 3 4 5 |
my_list = [['a', 'b'], [1, 2]] list(itertools.product(*my_list)) # [('a', 1), ('a', 2), ('b', 1), ('b', 2)] |