Python : Most efficient way to get list of combinations?
Question: I have a dictionary :

    
    
    diff_params = {0: [a, b], 
                   1: [c, d]}
    

Each key is a setting_name, and each value is a specific setting. I would like
to be able to make a list like:

    
    
    [[a, c], 
     [a, d],
     [b, c],
     [b, d]] 
    

I can't figure out how to do cleanly when I have 3 or 4 or 5 settings and each
setting has several options.


Answer: It seems that you are more specifically looking for
[`itertools.product()`](https://docs.python.org/3/library/itertools.html#itertools.product)
which can be used like this with
[unpacking](https://docs.python.org/3/tutorial/controlflow.html#unpacking-
argument-lists):

    
    
    from itertools import product
    
    result = product(*diff_params.values())
    

You may need to cast the result if you really want a list of list (surrounding
`list` is useless if you are using Python 2 because `map()` return a list):

    
    
    result = list(map(list, result))
    

