Find the position · Temukan posisi
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.
Temukan posisi
Cari dalam daftar dan laporkan di mana sesuatu berada, dihitung mulai dari 0.
Loopi melalui posisi dengan range(len(items)), sehingga Anda memiliki indeks i serta item items[i]. return langsung meninggalkan fungsi, yang merupakan hal yang tepat saat cocok pertama kali. Kembalikan -1 hanya setelah perulangan memeriksa setiap item.
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(). · Tulis find_index(items, target) yang mengembalikan posisi target pertama di dalam items, atau -1 jika tidak ada di sana. Jangan gunakan .index().
Click Run to see the output here. · Klik Jalankan untuk melihat output di sini.