0
Boas, Having the following list::
lista_nomes =['Manuel', 'Laura', 'Antonio', 'Jasmim', 'Maria','Silvia', 'Lu', 'Pancrácio', 'Diogo', 'Ricardo', 'Miguel', 'Andre',]
I want to print the list elements that have 5 letters.
Turns out I’m not getting it.
lista_nomes =['Manuel', 'Laura', 'Antonio', 'Jasmim', 'Maria',
'Silvia', 'Lu', 'Pancrácio', 'Diogo', 'Ricardo', 'Miguel', 'Andre',]
for elem in lista_nomes:
if elem == 5:
lista_valida.append(elem)
print (elem)
What you want is to check if the string (name) has 5 characters, not if
nome == 5
, This we know will not be. Uselen()
to see the length (how many characters) of the string– Miguel
'Cause...I thought it would work out that way.!
– Joao Peixoto Fernandes
And I think you also have to declare
lista_valida = []
before the for– Miguel
Yes, I do! My mistake of not doing it!
– Joao Peixoto Fernandes