Created
November 5, 2015 23:49
-
-
Save scuq/8cd6014869345587c5a5 to your computer and use it in GitHub Desktop.
dirty divide-and-conquer python function list_contains_fast.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def list_contains_fast(largelist,startwithstr): | |
listsize=len(largelist) | |
#print "list_contains_fast"+str(listsize) | |
if listsize <= 500: | |
for listentry in largelist: | |
if startwithstr.startswith(listentry): | |
return True | |
return False | |
currentpick_index=int(listsize/2) | |
currentpick=largelist[currentpick_index] | |
currentpick_len=len(currentpick) | |
compare_len=len(currentpick) | |
if currentpick_len > len(startwithstr): | |
compare_len = len(startwithstr) | |
if currentpick.startswith(startwithstr) == True: | |
return True | |
if startwithstr[0:compare_len] > largelist[currentpick_index][0:compare_len]: | |
return list_contains_fast(largelist[currentpick_index-1:],startwithstr) | |
else: | |
return list_contains_fast(largelist[:currentpick_index+1],startwithstr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment