0

Given the following lists:

A=['a','b','c']
B=[1,2]

I'd like to join the values such that each element of B is joined to each of A like this:

['a1','a2','b1','b2','c1','c2']

Thanks in advance!

0

2 Answers 2

1

A 1-liner works:

[x+str(y) for x in A for y in B] 
Sign up to request clarification or add additional context in comments.

Comments

1
A=['a','b','c']
B=[1,2]

C = []
for a in A:
    for b in B:
        C.append( str(a) + str(b) )
print(C)

Result:

['a1', 'a2', 'b1', 'b2', 'c1', 'c2']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.