You can use the replace
to replace unwanted characters in your string with an empty string:
'#[Header]'.replace('#', '') # '[Header]'
To do this in all strings in the list, just use a list comprehension to apply the replace
in all elements:
minha_lista = ['#[Header]', '#Application Name\tLCsolution', '#Version\t1.24']
minha_lista = [s.replace('#', '') for s in minha_lista]
Or do the same for just one Cup:
minha_lista = ['#[Header]', '#Application Name\tLCsolution', '#Version\t1.24']
minha_lista[:2] = [s.replace('#', '') for s in minha_lista[:2]]
And if I want to modify the list elements by accessing the element by their content?
– Bruno Santos
@Brunosantos can give an example of what it means?
– Pedro von Hertwig Batista
lista_original = ['#flower', '#leaf', '#stone', '#tree', '#storm'] How do I remove '#' from '#stone' and '#storm' without knowing their content in the list? Just knowing that I want to alter these elements, even without knowing where they are?
– Bruno Santos
@Brunosantos if understood well, just do
minha_lista[minha_lista.index('#pedra')] = 'pedra'
, orminha_lista[minha_lista.index('#pedra')] = '#pedra'.replace('#', '')
.– Pedro von Hertwig Batista
thank you!!!!!!!
– Bruno Santos