Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fragment(frag, word):
- if word.startswith(frag)==True:
- return True
- else: return False
- def exist_word(wordlist, frag, first, last):
- """
- Binary search.
- """
- print first, last, call, wordlist[last], frag
- mid = first + ((last-first)/2)
- print mid, wordlist[mid]
- ##End Test. Function runs until there are 2 words left
- ##Note: The wordlist[last] is always less than word fragment or, if it exists,
- ## 1 before the fragment. Therefore, compare with wordlist[last+1]
- if last-first<2:
- if wordlist[first]==frag or wordlist[last]==frag:
- return True
- elif fragment(frag, wordlist[last+1]) == False:
- return False
- else:
- return None
- if wordlist[mid] == frag:
- return True
- if wordlist[mid] > frag:
- return exist_word(wordlist, frag, first, mid-1)
- return exist_word(wordlist, frag, mid + 1, last)
Advertisement
Add Comment
Please, Sign In to add comment