First Matching Position

Finding an index is useful when you need to know not just whether an element exists, but where it is located. The function find_index receives a list of numbers nums and a number target. Return the index of the first occurrence of target, or -1 if it is not in the list.

Примеры

Ввод
([1, 2, 3], 2)
Вывод
1
Ввод
([1, 2, 3], 9)
Вывод
-1
Ввод
([], 1)
Вывод
-1

Нужно реализовать

def find_index(nums: list[int], target: int) -> int:

Теги

liststwo-pointers
PostgreSQLv16
Entre para enviar

O resultado da execução do código aparecerá aqui

Visible tests
1
Input
[1,2,3], 2
Expected1
2
Input
[1,2,3], 9
Expected-1
3
Input
[], 1
Expected-1
4
Input
[5,5,5], 5
Expected0
5
Input
[4,3,2,1], 1
Expected3
6
Input
[1,2,3], 1000
Expected-1
Focus radio
Paused · SomaFM · Fluid