View Full Version : Python: Is there a way to check if a word is a valid one based on a dictionary?
superpink99
June 12th, 2009, 02:32 AM
Hi, i was wondering if there was a way in python on checking if a certain word is an accepted word based on a dictionary?
example if i typed a word, is there a library where i can cross reference it if it is an acceptable word?
thanks..........
ghostdog74
June 12th, 2009, 02:46 AM
get the dictionary to a list. use the "in" operator
eg
if "word" in list_of_dictionary_words:
print "ok"
otherwise, use a database
benj1
June 12th, 2009, 02:50 AM
why are you starting multiple threads asking the same question?
you had the answer in the last thread.
superpink99
June 12th, 2009, 03:11 AM
sorry benj1, your right i should haver rephrased my first post.:)
ghostdog74: you said put the dictionary on a list? does that mean typing every word from the dictionary? where can i find a database of all the words?
thanks............:)
benj1
June 12th, 2009, 04:07 PM
as was answered in the other post
/usr/share/dict
contains the dictionarys
you need to learn about working with files
so
text = open("/usr/share/dict/british-english",'r').readlines()
for lines in text:
if lines.find("word") == 0:
print "word is in the dictionary"
benj1
June 12th, 2009, 04:31 PM
as was answered in the other post
/usr/share/dict
contains the dictionarys
you need to learn about working with files
so
text = open("/usr/share/dict/british-english",'r').readlines()
for lines in text:
if lines.find("word") == 0:
print "word is in the dictionary"
Powered by vBulletin® Version 4.2.2 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.