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
  • 69,116
  • 53
  • 210
  • 260
Ibe
  • 4,485
  • 6
  • 27
  • 44

1 Answers1

2

Try Python list comprehensions.

>>> a = ['1','2']
>>> b = 'a'
>>> [b+i for i in a]
['a1', 'a2']
Srikar Appalaraju
  • 69,116
  • 53
  • 210
  • 260