Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def insert_log(lst, item):
- placed = True
- low = 0
- top = len(lst)
- mid = top // 2
- while placed:
- index = lst[mid]
- if index == item:
- placed = False
- lst.insert(index, item)
- if lst[mid] > item > lst[mid-1]:
- placed = False
- lst.insert(mid, item)
- elif index > item:
- top = mid
- mid = (low + mid) // 2
- elif index < item:
- low = mid
- mid = low + ((top - low) // 2)
- return lst
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement