grandfathermagic

פונקציה שמחזירה את המיקום האחרון של האיבר אותו אנחנו מחפשים

May 10th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. # כתבו פונקציה שמקבלת רשימה, ומחזירה את מיקום המופע האחרון של האיבר הראשון ברשימה.
  2. # לדוגמה, עבור הרשימה [1, 2, 3, 5, 1, 2] החזירו 4, כיוון ש־1 מופיע פעם אחרונה במקום 4 ברשימה.
  3. #
  4. test_list = ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r','g', 'e', 'e', 'k', 's']
  5. find_me = 'e'
  6. place = 0
  7. i = 0
  8. while i < len(test_list):
  9.     if find_me == test_list[i]:
  10.         place = i
  11.     i += 1
  12. print(place)
Advertisement
Add Comment
Please, Sign In to add comment