Member Avatar for leegeorg07

Hi I have this code currently:

dict  = open("dict.txt", "r").readlines()
print dict
LETTERS={'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8, 'i':9, 'j':10, 'k':11, 'l':12, 'm':13, 'n':14, 'o':15, 'p':16, 'q':17, 'r':18, 's':19, 't':20, 'u':21, 'v':22, 'w':23, 'x':24, 'y':25, 'z':26}
word_value=0
lettersv=[]
letterss=[]

def main():
    word=raw_input('what is the word?')

    word=word.lower()
    for i in range(len(dict)):
        dict[i] = dict[i][0:len(dict[i])-2]

    if word in dict:
        for letter in word:
            lettersv.append(LETTERS[letter])
            letterss.append(letter)
        print '*'*40
        print letterss
        print '*'*40
        word_value=sum(lettersv)
        print lettersv, word_value
        print '*'*40
    else:
        print "that word is not in the english dictionary, sorry."

while 1:
    main()

but whenever I try to test, it wont recognise words like 'english' Does anyone know how to fix this? thanks in advance.

Recommended Answers

All 4 Replies

for i in range(len(dict)):
        dict[i] = dict[i][0:len(dict[i])-2]

What is that? What are you doing?

EDIT: Also remember that dict is a reserved word in Python I suggest that you change the name

Member Avatar for leegeorg07

i'm not sure actually, i mainly copied and pasted from a previous thread about a spell checker I made

Why so complicated?
Using a similar english dictionary file:

# mydict.txt has one English word per line
# about 74500 in total
mydict  = open("mydict.txt", "r").readlines()

print(mydict[:10])

"""my display of some words in mydict -->
['aardvark\n', 'aardvarks\n', 'aaron\n', 'abaci\n', ... ]
"""

# strip the trailing newline char
mydict = [w.rstrip() for w in mydict]

print(mydict[:10])

"""my display -->
['aardvark', 'aardvarks', 'aaron', 'abaci', ... ]
"""

# test one word
word = 'aaron'

if word in mydict:
    print("word found")  # word found
Member Avatar for leegeorg07

thanks that worked much better :) problem solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.