Найди иголку
Представь большой список, где среди случайных значений спряталась строка needle. Напиши функцию find_needle, которая найдёт индекс этой строки в списке haystack. Верни готовую фразу в формате found the needle at position p, где p — найденный индекс.
Примеры
Ввод
["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
Войдите, чтобы видеть историю отправок
ВойтиВойдите, чтобы использовать AI Mentor
ВойтиВидимые тесты
1
Ввод
["3","123124234",null,"needle","world","hay",2,"3",true,false]Ожидаемый
"found the needle at position 3"2
Ввод
["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"3
Ввод
["needle"]Ожидаемый
"found the needle at position 0"4
Ввод
[1,2,3,"needle"]Ожидаемый
"found the needle at position 3"5
Ввод
["hay","needle","hay"]Ожидаемый
"found the needle at position 1"6
Ввод
["3","123124234",null,"needle","world","hay",2,"3",true,false,"3","123124234"]Ожидаемый
"found the needle at position 3"Фокус-радио
На паузе · SomaFM · Fluid