from __future__ import print_function

def binary_search(a_list, item):
    """Binary search."""
    pass


def main():
    import time
    a_list = [54, 26, 93, 17,77, 31, 44, 55, 20, 65]
    print('a_list: {}'.format(a_list))

    start_time = time.time()
    item = None
    print('Search item {0}: {1}'
          .format(item, binary_search(a_list, item)))


if __name__ == '__main__':
    main()

@@ -89,274 +89,1887 @@
 arch
-.%22%22%22%0A    pass%0A%0A%0Adef main():%0A    import time%0A    a_list = %5B54, 26, 93, 17,77, 31, 44, 55, 20, 65%5D%0A    print('a_list: %7B%7D'.format(a_list))%0A%0A    start_time = time.time()%0A    item = None%0A    print('Search item %7B0%7D: %7B1%7D'%0A          .format(item, binary_search(a_list, item)
+ for ordered list.%22%22%22%0A    first = 0%0A    last = len(a_list) - 1%0A    found_flag = False%0A%0A    while first %3C= last and not found_flag:%0A        mid_point = (first + last) // 2%0A        if a_list%5Bmid_point%5D == item:%0A            found_flag = True%0A        else:%0A            if item %3C a_list%5Bmid_point%5D:%0A                last = mid_point - 1%0A            else:%0A                first = mid_point + 1%0A%0A    return found_flag%0A%0Adef binary_search_by_recur(a_list, item):%0A    %22%22%22Binary search for ordered list by recursion.%22%22%22%0A    if len(a_list) == 0:%0A        return False%0A    else:%0A        mid_point = len(a_list) // 2%0A        if a_list%5Bmid_point%5D == item:%0A            return True%0A        else:%0A            if item %3C a_list%5Bmid_point%5D:%0A                return binary_search_by_recur(a_list%5B:mid_point%5D, item)%0A            else:%0A                return binary_search_by_recur(a_list%5B(mid_point + 1):%5D, item)%0A%0A%0Adef main():%0A    import time%0A%0A    start_time = time.time()%0A    a_list = %5B54, 26, 93, 17,77, 31, 44, 55, 20, 65%5D%0A    print('a_list: %7B%7D'.format(a_list))%0A    # Sort the list.%0A    a_list = sorted(a_list)%0A    print('Sorted a_list: %7B%7D'.format(a_list))%0A    print('Time for sorted(): %7B%7D'%0A          .format(time.time() - start_time))   %0A%0A    start_time = time.time()%0A    item = None%0A    print('Search item %7B0%7D: %7B1%7D'%0A          .format(item, binary_search(a_list, item)))%0A    item = 93%0A    print('Search item %7B0%7D: %7B1%7D'%0A          .format(item, binary_search(a_list, item)))%0A    print('Time for binary_search(): %7B%7D'%0A          .format(time.time() - start_time))%0A%0A    start_time = time.time()%0A    item = None%0A    print('Search item %7B0%7D: %7B1%7D'%0A          .format(item, binary_search_by_recur(a_list, item)))%0A    item = 93%0A    print('Search item %7B0%7D: %7B1%7D'%0A          .format(item, binary_search_by_recur(a_list, item)))%0A    print('Time for binary_search_by_recur(): %7B%7D'%0A          .format(time.time() - start_time
 ))%0A%0A

Complete binary_search() by naive & recursion