Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. my_list = [3, 5, 5, 2, 8, 6, 6, 9, 3, 7]
  2.  
  3. def linear_search(my_list):
  4.     position = 0
  5.     while position < len(my_list):
  6.         print(my_list[position], "is at position", str(position))
  7.         if my_list[position] == 6:
  8.             print("Found at position", str(position))
  9.             return position
  10.         else:
  11.             position = position + 1
  12.     print("Not found")
  13.     return False
  14.  
  15. linear_search(my_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement