2 votes

How do I remove the first three letters of a list from each of the items?

I try to delete the first three numbers / letters from a list with the str(x[:3]) :

 lista=['Jueves1', '2martes', '30miércoles', 'Jueves23']
resultado=lista[3:]
print(resultado)

If I do it with a single item from the list, it does remove it:

 un_solo_elemento=['Jueves1']
resultado=un_solo_elemento[3:]
print(resultado)

My question here is, how can I do this for each of the items found within the list? In such a way that I print: ['ves1', 'rtes', 'iércoles', 'ves23']

Thank you very much in advance and greetings.

2voto

aeportugal Points 1058

Another way using map and an anonymous function :

 nueva_lista = list(map(lambda x:x[3:], lista))

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X