Find the position · Encontrar a posição
Find the position
Search a list and report where something is, counting from 0.
Loop over the positions with range(len(items)), so you have the index i as well as the item items[i]. return leaves the function straight away, which is exactly what you want at the first match. Return -1 only after the loop has checked every item.
Encontrar a posição
Pesquise uma lista e informe onde algo está, contando a partir de 0.
Percorra as posições com range(len(items)), para ter o índice i além do item items[i]. return sai da função imediatamente, o que é exatamente o que se deseja na primeira correspondência. Retorne -1 apenas após o loop verificar todos os itens.
Write find_index(items, target) that returns the position of the first · primeiro target in items, or -1 if it is not there. Do not use .index(). · Escreva find_index(items, target) que retorna a posição do primeiro target em items, ou -1 se não estiver lá. Não use .index().
Click Run to see the output here. · Clique em Executar para ver a saída aqui.