lundi 30 décembre 2019

Add string to each item in python list based on condition

I want to add the string " Equity" to each item in a list if the third last character in the item is " ". Otherwise, I would like to add " Index". Ideally, I don't want to use loops if there is a way.

For Example, I want the list below

list = ['VOD LN','HSBA LN', 'DOKA SS','SXNE' 'KERIN FH','YORK GY','SXNP']

to look like the list below

list = ['VOD LN Equity','HSBA LN Equity', 'DOKA SS Equity','SFNE Index' 'KERIN FH Equity','YORK GY','SXKP Index']

Any idea how i can do this?

Thanks!

Aucun commentaire:

Enregistrer un commentaire