----- Messaggio originale -----
> Da: "Tutor Python" <tutor@python.org>
> A: "Tutor Python" <tutor@python.org>
> Inviato: Sabato, 28 luglio 2018 0:06:55
> Oggetto: Re: [Tutor] Do something on list elements

> But better still is a list comprehension:
> 
> l = [s.replace('X','') for s in l)
> print(l)

Thank you all for the answers.
List comprehension is what I was looking for.

Here's almost the same example that I made up to summarize:

>>> l = ['one ', 'two ', 'three ']
>>> print(l)
['one ', 'two ', 'three ']

>>> l = [ s.strip() for s in l]
>>> print(l)
['one', 'two', 'three']

I create a new list with the same name so I don't need to have another list.
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to