View difference between Paste ID: ZNeFjcVE and PXpvB1Qr
SHOW: | | - or go back to the newest paste.
1-
import random
1+
2
    if word.startswith(frag)==True:
3-
# -----------------------------------
3+
4-
# Helper code
4+
5-
# (you don't need to understand this helper code)
5+
6
def exist_word(wordlist, frag, first, last):
7-
import string
7+
8
    Binary search. 
9-
WORDLIST_FILENAME = "words.txt"
9+
10
    
11-
def load_words():
11+
    print first, last, call, wordlist[last], frag
12
    mid = first + ((last-first)/2)
13-
    Returns a list of valid words. Words are strings of lowercase letters.
13+
    print mid, wordlist[mid]
14-
    Depending on the size of the word list, this function may
14+
   
15-
    take a while to finish.
15+
16
    ##Note: The wordlist[last] is always less than word fragment or, if it exists,
17-
    print "Loading word list from file..."
17+
    ## 1 before the fragment. Therefore, compare with wordlist[last+1]  
18-
    # inFile: file
18+
19-
    inFile = open(WORDLIST_FILENAME, 'r', 0)
19+
20-
    # wordlist: list of strings
20+
21-
    wordlist = []
21+
22-
    for line in inFile:
22+
23-
        wordlist.append(line.strip().lower())
23+
24-
    print "  ", len(wordlist), "words loaded."
24+
25-
    return wordlist
25+
26
    
27-
def get_frequency_dict(sequence):
27+
28
            return True
29-
    Returns a dictionary where the keys are elements of the sequence
29+
30-
    and the values are integer counts, for the number of times that
30+
31-
    an element is repeated in the sequence.
31+
    return exist_word(wordlist, frag, mid + 1, last)