0

I have a string which I want to concatenate with every object within a list. Here is an example:

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

and I want:

c = ['a1','a2']

It seems that strings can't be concatenated to list objects directly so I assume that I should convert my list to the string and then add it. Is it correct or any suggestions?

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
Ibe
  • 5,615
  • 7
  • 32
  • 45

1 Answers1

2

Try Python list comprehensions.

>>> a = ['1','2']
>>> b = 'a'
>>> [b+i for i in a]
['a1', 'a2']
Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264