Q:

Fastest way to index an element in a sorted list in python?

Python's lists have a function list.index(elem) which, to the best of my knowledge, run in O(n) time. However, if I can guarantee the list to be sorted, is this still the best way to get the index of an element? 
Will a binary search return the index faster? Also, is there a way to force the python Standard library to do a binary search for the index of an element in a list? 

A:

Yes, a binary search will generally be faster. No, the standard library index function has no option for that.
Another answer has code for a binary search:
from bisect import bisect_left

def binary_search(a, x, lo=0, hi=None):   # can't use a to specify default for hi
    hi = hi if hi is not None else len(a) # hi defaults to len(a)   
    pos = bisect_left(a,x,lo,hi)          # find insertion position
    return (pos if pos != hi and a[pos] == x else -1) # don't walk off the end

