Finding an element in a list
If your list is sorted you can use binary search (your second code), and it will be faster for large lists, but if it's unsorted you'll have to keep to linear search. The Python library provides fast implementation of both methods, so you really don't need to roll your own:

&gt;&gt;&gt; a = range(10)

&gt;&gt;&gt; a.index(4) # linear search
4

&gt;&gt;&gt; import bisect
&gt;&gt;&gt; idx = bisect.bisect(a, 4) # binary search
&gt;&gt;&gt; if a[idx-1] == 4:
...     print idx - 1
... else:
...     raise ValueError('item not in list')
... 
4