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) ترجع موقع أول target في items، أو -1 إذا لم يكن موجودًا. لا تستخدم .index().
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.