Python : Most efficient way to get list of combinations? -


i have dictionary :

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

each key setting_name, , each value specific setting. able make list like:

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

i can't figure out how cleanly when have 3 or 4 or 5 settings , each setting has several options.

it seems more looking itertools.product() can used unpacking:

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

you may need cast result if want list of list (surrounding list useless if using python 2 because map() return list):

result = list(map(list, result)) 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -