AutoComplete plugin part 2
2
When given the start of a string it searches the wordlist and returns the most popular word used beginning with that string. Designed to be used in autocomplete IM plugin where tab would cycle through used words beginning with the string, in order of popularity.
#Part 2 - Taking the start of a word and providing hte most common word from it
import sys
import operator
string = raw_input("Enter the start of the word:")
readme=open("dict.txt", "r")
readfile=readme.read()
if readfile.count(string) == 0:
print "Error not in wordlist"
sys.exit(1)
startval=0
ndict={}
for i in range(readfile.count(string)):
firstpos=readfile.index(string, startval)
endword=readfile.index(",", firstpos)
freq=readfile[endword+1]
word = readfile[firstpos:endword] #Okay now add these to dictionary
#print freq
#Now get numbers after and compare or something
#This is not ideal in a for loop - maybe use array or something
ndict[word] = freq
startval=endword
test= ndict.items()
test.sort(key=operator.itemgetter(1))
test.reverse()
print test[0][0]






There are currently no comments for this snippet.