Need a little help here, if anyone can offer any advice. The problem I have is this. I have a dictionary that contains keys, and their possible values. I need to generate every possible combination of key values where each key can take on one of the possible values.(adsbygoogle = window.adsbygoogle || []).push({});

For example, the dictionary might look something like:

So, for the "1" key, the possible values it can assume are A, B, and C. For the "2" key, the possible values it can assume are D, E, F, G, and H. This continues for all keys, of undefined number of possible values. For this example, the number of possible combinations is something of the form: 3*5*2*4*3 = 360.Code (Text):Value Dictionary: {1: [[A], [B], [C]], 2: [[D], [E], [F], [G], [H]], 3: [[I], [J]], 4: [[K], [L], [M], [N]], 5: [[O], [P], [Q]]}

I need a way to output a 2D list containing every possible combination. So, the algorithm would output something like:

Where the length of the combination list would be 360 and the width would be 5.Code (Text):Combination List: [[A,D,I,K,O], [A,D,I,K,P], [A,D,I,K,Q], [A,D,I,L,O],...,[C,H,J,N,Q]]

Does python have any built in way to do this, or will I have to come up with some logic to do this by hand? If I have to do it by hand, does anyone have any recommendations? I'm guessing recursion might be the best way to do this, but I'm not sure.

**Physics Forums | Science Articles, Homework Help, Discussion**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Python: Generating All Possible Combinations?

Loading...

Similar Threads for Python Generating Possible |
---|

Python for vector files |

Practicing Python and R at the same time |

Python (VPython) Can someone help me with my orbit simulator? |

Python Create a sign-out sheet in Python |

Python How can I run Python by getting values from Matlab |

**Physics Forums | Science Articles, Homework Help, Discussion**