How to get 2D array possible combinations

前端 未结 5 2067
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-17 20:18

I have the following 2D array:

String[M][]

String[0]
   \"1\",\"2\",\"3\"

String[1]
   \"A\", \"B\"
   .
   .
   .
String[M-1]
   \"!\"

A

5条回答
  •  旧巷少年郎
    2020-12-17 20:43

    In Python one uses itertools.product and argument unpacking (apply)

    >>> import itertools
    >>> S=[['1','2','3'],['A','B'],['!']]
    >>> ["".join(x) for x in itertools.product(*S)]
    ['1A!', '1B!', '2A!', '2B!', '3A!', '3B!']
    

提交回复
热议问题