0
Basically I want to remove the elements from a second list based on the result of another list. I have two lists:
lista_8 = ['', '', 'Preco', '', 'Preco', '', '', 'Preco']
lista_n = ['positivo', 'positivo', 'negativo', 'positivo', 'negativo', 'positivo', 'positivo', 'negativo']
Follows the logic:
When the element of lista_8
is empty, the element of the lista_n
also becomes empty, otherwise keeps the result (positive or negative).
My code is like this:
for w in lista_8:
if lista_8[w] == 0:
lista_n[w+1] = 0
print lista(n)
Follow error that happens:
if lista_8[w] == 0:
Typeerror: list indices must be integers or Slices, not str
The
w
represents each element oflista_8
, is not the index. You will need to use theenumerate
to manipulate the index. https://www.geeksforgeeks.org/enumerate-in-python/– Camilo Santos
Are you trying to walk the
lista_8
with thefor
, when you try to check whetherlista_8
in positionw
, error occurs because it expects an integer number of the position in the list.– sant0will