Answer the question
In order to leave comments, you need to log in
How to generate all possible combinations from two lists?
Good afternoon!
There are two lists:
atoms = ['Co1', 'Co2', 'Co3', 'Co4', 'Co5', 'Co6', 'Co7', 'Co8']
dopedatoms = ['Mn1', 'Mn2', 'Mn3', 'Mn4', 'Mn5', 'Mn6', 'Mn7', 'Mn8']
['Co8', 'Co2', 'Co3', 'Co4', 'Co5', 'Co6', 'Co7', 'Mn1']
['Co8', 'Co1', 'Co3', 'Co4', 'Co5', 'Co6', 'Co7', 'Mn2']
['Co8', 'Co1', 'Co2', 'Co4', 'Co5', 'Co6', 'Co7', 'Mn3']
['Co8, 'Co1', 'Co2', 'Co3', 'Co5', 'Co6', 'Co7', 'Mn4']
['Co8', 'Co1', 'Co2', 'Co3', 'Co4', 'Co6', 'Co7', 'Mn5']
['Co8', 'Co1', 'Co2', 'Co3', 'Co4', 'Co5', 'Co7', 'Mn6']
и т.д.
['Co8', 'Co2', 'Co3', 'Co4', 'Co5', 'Co6', 'Mn7', 'Mn1']
['Co1', 'Co7', 'Co8', 'Co4', 'Co5', 'Co6', 'Mn3', 'Mn2']
...
и т.д.
['Co1, 'Co2', 'Co3', 'Co4', 'Co5', 'Co6', 'Mn1', 'Mn2']
['Co1', 'Co7', 'Co8', 'Co4', 'Co5', 'Co6', 'Mn7', 'Mn8']
...
и т.д.
comb1 = itertools.combinations(atoms, 6)
comb2 = itertools.combinations(dopedatoms, 2)
result = itertools.product(comb1, comb2)
but this results in duplicate elements.
Answer the question
In order to leave comments, you need to log in
With a clarification about the repetition of digits, this is equivalent to iterating over combinations of
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0
0 0 0 0 0 0 1 1
...
1 1 1 1 1 1 1 1
(total 256 combinations),
where 0 means that we take an element from atoms,
1 means that we take an element from dopedatoms, for example
1 0 0 0 0 0 0 0 corresponds to ['Mn1', 'Co2', 'Co3', 'Co4', 'Co5', 'Co6', 'Co7', 'Co8']
So you can loop from 0 to 255, split the loop variable into bits, and form combinations bit by bit.
The conditions do not mention the boundary cases 0 0 0 0 0 0 0 0 and 1 1 1 1 1 1 1 1, if they are not needed, then loop from 1 to 254.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question