(Nov-04-2016, 12:31 AM)salmanfazal01 Wrote: I've used the enumeration function but that is not efficient.Obviously if you use a O(n) method to attempt to speed up a O(logn) algorithm it isn't going to help. Basically your only choice to find those indexes is also a binary search. You can use the bisect module.
from bisect import bisect myList = [1,4,5,6,9,10,12,14,16,19,20,22,23,24,29,30] low = bisect(myList, int(input("Enter number with which to bisect: "))) print(low)Honestly I don't think this will help one bit, but it at least keeps the overall complexity of your code down to O(logn). O(logn) is incredibly fast so I don't think this will make any noticeable change whatsoever; just search the whole list. Also using an implementation of binary search to implement binary search is a little silly to say the least.