Print One to many between 2 lists

Question:

Sorry for the wrong output sequence. The one that i changed now has the correct one.

I have two lists in Python as given below

a = ['a','b','c']
b = [1,2,3]

I want to print the output as

a1,b1,c1,a2,b2,c2,a3,b3,c3.

How can I achieve this?

Asked By: user537644

||

Answers:

You could simply use for loops, as below:

a = ['a','b','c']
b = [1,2,3]

for el_a in a:
    for el_b in b:
        print str(el_a) + str(el_b)

will produce :

a1,a2,a3, b1,b2,b3, c1,c2,c3

[Update]
For the updated sequence:

a = ['a','b','c']
b = [1,2,3]

for el_b in b:
    for el_a in a:
        print str(el_a) + str(el_b)

will produce :

a1,b1,c1, a2,b2,c2, a3,b3,c3
Answered By: Lorenzo Addazi

Try this.

for i in a:
    for j in b:
        print a+b

Hope this helps.

Answered By: Harv
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.