Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: to prolong elements in a list

Tags:

python

list

I am trying to create a new list based on the old one, from ['a','b','c'] to ['a12', 'b12', 'c12'].

a classic way can be:

a = ['a','b','c']
aa = []

for item in a:
    aa.append(item + '12')

print aa

however I want to learn a better way so I tried:

aa = a.extend('12%s' % item for item in l[:])

and

aa = [item.join('12') for item in l]

but they don't produce the most correct one. what are the better ways?

thanks.

like image 786
Mark K Avatar asked Dec 12 '25 01:12

Mark K


1 Answers

aa = [item + '12' for item in a]

like image 54
wRAR Avatar answered Dec 13 '25 14:12

wRAR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!