0
list1=['A','B']

list2=[1,2,3]

How do I make it so the output shows all possible combinations in this order and without any brackets?

A1

A2

A3

B1

B2

B3
Sociopath
  • 13,068
  • 19
  • 47
  • 75
RRR
  • 21
  • 1

3 Answers3

1

You can use itertools.product:

from itertools import product
list1 = ['A', 'B']
list2 = [1, 2, 3]
for e1,e2 in product(list1, list2):
    print(e1+str(e2))

Output:

A1
A2
A3
B1
B2
B3
Sayandip Dutta
  • 15,602
  • 4
  • 23
  • 52
0

You may use:

list3 = [a+b for a in list1 for b in map(str, list2)]
print(*list3, sep = "\n") 
A1
A2
A3
B1
B2
B3
luigigi
  • 4,146
  • 1
  • 13
  • 30
0

You can use:

list1 = ['A', 'B']
list2 = [1, 2, 3]
for i in list1:
    for j in list2:
        print(i+str(j))
xcen
  • 652
  • 2
  • 6
  • 22