Reputation: 31
I am trying to figure out how to print all the combinations there are for multiple sets of letters without repetition.
An example: A,B,C and X,Y,Z
The combinations would be:
AX AY AZ BX BY BZ CX CY CZ
Upvotes: 3
Views: 271
Reputation: 106480
You can use itertools.product
to get what you want.
from itertools import product
a = ['A', 'B', 'C']
b = ['X', 'Y', 'Z']
for i in product(a, b):
print ''.join(i)
Upvotes: 8
Reputation: 191789
You could just loop over both sets:
for a in abcstring:
for x in xyzstring:
print a + x
Upvotes: 0