Skip to content · ⁨Pular para o conteúdo⁩

Find the position · ⁨Encontrar a posição⁩

English

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.

Português

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.

Log in or create account · ⁨Entrar ou criar conta⁩

IGCSE, A-Level & AP