Find the Needle

Imagine a large list where the string needle is hidden among random values. Write a function find_needle that finds the index of this string in the list haystack. Return the ready-made phrase found the needle at position p, where p is the found index.

Примеры

Ввод
["3", "123124234", None, "needle", "world", "hay", 2, "3", True, False]
Вывод
"found the needle at position 3"
Ввод
["283497238987234", "a dog", "a cat", "some random junk", "a piece of hay", "needle", "something somebody lost a while ago"]
Вывод
"found the needle at position 5"
Ввод
["needle"]
Вывод
"found the needle at position 0"

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

def find_needle(haystack: list) -> str:

Теги

listsarraystrings
PostgreSQLv16

Tu sa zobrazí výsledok spustenia kódu

Visible tests
1
Input
["3","123124234",null,"needle","world","hay",2,"3",true,false]
Expected"found the needle at position 3"
2
Input
["283497238987234","a dog","a cat","some random junk","a piece of hay","needle","something somebody lost a while ago"]
Expected"found the needle at position 5"
3
Input
["needle"]
Expected"found the needle at position 0"
4
Input
[1,2,3,"needle"]
Expected"found the needle at position 3"
5
Input
["hay","needle","hay"]
Expected"found the needle at position 1"
6
Input
["3","123124234",null,"needle","world","hay",2,"3",true,false,"3","123124234"]
Expected"found the needle at position 3"
Focus radio
Paused · SomaFM · Fluid