Reputation: 923
I am just starting learn python. Please advise how I can concatenate this.
a='abc'
b='123'
As output I want:
[(a1, b2, c3)]
I tried to use built in zip()
function but result is (a, 1), (a, 2), (a, 3)
Upvotes: 2
Views: 5836
Reputation: 1518
Because you can directly addup two string together, therefore you can try:
[x+y for x,y in zip(a,b)]
Upvotes: 4
Reputation: 12015
You can use ''.join
and map. Would come handy when you have to join more that 2 elements
>>> list(map(''.join, zip(a,b)))
['a1', 'b2', 'c3']
Upvotes: 0
Reputation: 195438
You need to concatenate the values after zip
:
a='abc'
b='123'
print([v1 + v2 for v1, v2 in zip(a, b)])
Prints:
['a1', 'b2', 'c3']
Upvotes: 1