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

Combination of elements of different lists or tuples

hope you can help me think of a solution to this problem
I would like to get all the possible combinations between the elements of different lists or arrays
lets say I have
L1 = [A,B] and
L2 = [C,D]

if I somehow use itertool.combinantion for python to look for the combination for two elements the results would be {AB,AC,AD,BC,BD,BC}, the issue here is that I just need {AC,AD,BC,BD} because they are elements from different lists, is there a conditional or something that could help me get combinations of n elements from different lists?
hope I made myself clear enough, I am relatively new to coding,
thanks in advance,
Appreciate every response

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 :

Perhaps itertools.product:

>>> from itertools import product
>>> L1 = ['A', 'B']
>>> L2 = ['C', 'D']
>>> list(product(L1, L2))
[('A', 'C'), ('A', 'D'), ('B', 'C'), ('B', 'D')]
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