0
I do not understand what is happening with this excerpt of code. What was expected was that when imprint the list at the end he the elements of her split, but is returning the list as if nothing had happened.
(Each element of the initial list is a phrase. when I give . split() I want him to turn each of these elements into a new list where the words are separated)
x = open ('exemplo1.txt','r')
lista = x.readlines()
for l in lista:
l = l.split()
print(lista)
The list is not changed at any time, for all intents and purposes is as if your
for
did not exist. For what you want to see is the variablel
but print thelista
. You can put oneprint(l)
within thefor
to see the result ofstr.split()
– fernandosavio