Skip to content

Instantly share code, notes, and snippets.

@sridatta
Last active October 27, 2015 20:56
Show Gist options
  • Save sridatta/3e66b2a3025ef94c6e96 to your computer and use it in GitHub Desktop.
Save sridatta/3e66b2a3025ef94c6e96 to your computer and use it in GitHub Desktop.
def process_list_2(list_of_items):
s = set()
rv = []
for item in list_of_items:
if item not in s:
rv.append(item)
return s
def fun(sorted_list, needle):
def fun_internal(low, high):
if not sorted_list:
return None
if low >= high:
return None
pivot_pos = (low + high) / 2
if pivot_pos >= len(sorted_list):
return None
elif pivot_pos < 0:
return None
pivot = sorted_list[pivot_pos]
if needle == pivot:
return pivot
elif needle < pivot:
return fun_internal(low, pivot_pos - 1)
else:
return fun_internal(pivot_pos + 1, high)
return fun_internal(0, len(sorted_list) - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment