Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading