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().
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。