Find the position · Найти позицию
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.
Найти позицию
Найдите в списке и укажите где находится элемент, нумерация начинается с 0.
Проходите по позициям с помощью range(len(items)), чтобы получить одновременно индекс i и элемент items[i]. return немедленно завершает функцию, что именно и требуется при первом совпадении. Возвращайте -1 только после того, как цикл проверил все элементы.
Write find_index(items, target) that returns the position of the first target in items, or -1 if it is not there. Do not use .index(). · Напишите find_index(items, target), которая возвращает позицию первого occurrences ⟨target⟩ в ⟨items⟩ или -1, если его там нет. Не используйте .index().
Click Run to see the output here. · Нажмите Запустить, чтобы увидеть результат здесь.