Python combination of n dimensional array elements

I have a list of arrays as below

list1 = [['01', '02', '03', '04', '05', '06'], ['01', '64', '2f'], ['00', '1f', '17']]

I need all the possible combination of these elements like

010100, 01011f, 010117, 010200, 01021f, etc.

>Solution :

You can use itertools.product and get what you want:

import itertools

list1 = [['01', '02', '03', '04', '05', '06'], ['01', '64', '2f'], ['00', '1f', '17']]

for prd in itertools.product(*list1):
    print(''.join(prd))

Output:

010100
01011f
010117
016400
01641f
016417
012f00
...
062f00
062f1f
062f17

Leave a Reply