Advertisement
darkhorse5475

Untitled

Oct 13th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. # my linear search (for unsorted sequence of integers, starting position 0):
  2.  
  3. from random import randint
  4.  
  5. def my_linear_search(unsorted, searchval):
  6. sorted_list = sorted(unsorted)
  7. for position, item in enumerate(sorted_list):
  8. if sorted_list[position] == searchval:
  9. print(item, "is at position", position)
  10. if item > searchval:
  11. return False
  12.  
  13. list_to_sort = [randint(0,100) for i in range(500)]
  14. print(list_to_sort)
  15. my_linear_search(list_to_sort, 50)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement