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

后端 未结 1 483
时光说笑
时光说笑 2021-02-13 05:08

I have the following structure in Python:

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

I would like t

1条回答
  •  迷失自我
    2021-02-13 05:54

    In Python 2.6 or newer you can use itertools.product:

    >>> import itertools
    >>> map(''.join, itertools.product(*letters))
    apj
    apk
    apl
    aqj
    aqk
    aql
    ...etc...
    csk
    csl
    

    0 讨论(0)
提交回复
热议问题