3

I've been playing around with various modules (e.g. PyEnchant), and what I want to do is determine if a string is the beginning of an English word. E.g.

Smo -> Smoke
A x -> x-ray 
Elx -> NULL
Don -> Done
Brj -> NULL
Bes -> Besiege
Nix -> Nixed 

But I'm unsure if there is a way to do it, without creating and loading my own word list.

Darkstarone
  • 4,590
  • 8
  • 37
  • 74

1 Answers1

3

Python does not ship with it's own word list, so you would have to load it from somewhere (whether it's a common dictionary, a custom list, etc.).

Now I'm not sure about PyEnchant, but the easiest way to then do this is to create a Trie structure within Python as then checking if a word exists is as easy as going through graph nodes till either you hit a null (return False for word existing with that prefix) or you hit the last character in your search string (return True for word existing with that prefix.) A sample on making a Trie can be found in this thread.

Community
  • 1
  • 1
MasterOdin
  • 7,117
  • 1
  • 20
  • 35