How to get the length of an itertools.product?

前端 未结 4 984
無奈伤痛
無奈伤痛 2021-02-18 18:14

I am using itertools to run a numerical simulation iterating over all possible combinations of my input parameters. In the example below, I have two parameters and

4条回答
  •  梦如初夏
    2021-02-18 18:47

    Alternative solution I used:

    import itertools
    
    param = (('a', 'b'), (1, 2)) # a list of lists
    
    # Calculate all combinations
    combinations = itertools.product(*param)
    
    # Calculate number of combinations
    total_combinations = 1
    for i in param:
        total_combinations = total_combinations * len(i)
    

提交回复
热议问题