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. · לחץ על הרץ כדי לראות את התוצא כאן.