tags:

views:

83

answers:

3

Hi!

I got this list looking something like this

words = ['how', 'much', 'is[br]', 'the', 'fish[br]', 'no', 'really']

What I would like is to replace the [br] with some fantastic value similar to <br /> and thus getting a new list looking like this

words = ['how', 'much', 'is<br />', 'the', 'fish<br />', 'no', 'really']

I've laborated a lot by now so a little help would be appreciated!

Thanks!

+6  A: 

You can use, for example:

words = [word.replace('[br]','<br />') for word in words]
houbysoft
+10  A: 

words = [w.replace('[br]', '<br />') for w in words]

called List Comprehensions

sberry2A
Thank you so much!
Trikks
+2  A: 

Beside list comprehension, you can try map

>>> map(lambda x: str.replace(x, "[br]", "<br/>"), words)
['how', 'much', 'is<br/>', 'the', 'fish<br/>', 'no', 'really']
Anthony Kong