Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | None | 0 0
  1. def sort_search(sequence, value):
  2.     sequence=sorted(sequence)
  3.     position = 0
  4.     for item in sequence:
  5.         if value < item :#break if bigger item found  
  6.             print("False")
  7.             break
  8.         else:
  9.             if value != item:
  10.                 position += 1
  11.                 if position == len(sequence): #if value is bigger than all items
  12.                     print("False")
  13.                     break
  14.             else:
  15.                 print(item, "is at position", position, "of sorted sequence")
  16.                 break
  17.            
  18.  
  19. my_list = [5, 3, 7, 9, 2, 1]
  20. number = 9
  21. sort_search(my_list, number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement