#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]