How can I find all the possible combinations of a list of lists (in Python)?

Posted by Pheter on Stack Overflow See other posts from Stack Overflow or by Pheter
Published on 2010-06-07T13:43:31Z Indexed on 2010/06/07 13:52 UTC
Read the original article Hit count: 239

Filed under:

I have the following structure in Python:

letters = [['a', 'b', 'c'], ['p', 'q', 'r', 's'], ['j', 'k', 'l']]

I would like to find all the possible combinations of letters in the order that they currently exist. For the example above this would be:

apj
apk
apl
aqj
aqk
aql
...
csk
csl

This seems like it should be a very simple thing to do but I cannot figure it out.

© Stack Overflow or respective owner

Related posts about python