Find the position · Encontrar la posición
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 la posición
Busca en una lista e informa dónde se encuentra algo, contando desde 0.
Recorre las posiciones con range(len(items)), de modo que tengas tanto el índice i como el elemento items[i]. La instrucción return sale inmediatamente de la función, lo cual es exactamente lo que deseas al encontrar la primera coincidencia. Retorna -1 únicamente después de que el bucle haya revisado cada elemento.
Write find_index(items, target) that returns the position of the first · primero target in · hacia adentro items, or -1 if it is not there. Do not use .index(). · Escribe find_index(items, target) que devuelva la posición del primer target en items, o -1 si no está. No uses .index().
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.