Sean.D
Sean.D

Reputation: 97

enchant.errors.Error: Don't pass bytestrings to pyenchant-python

I am trying to make a program where I can enter some characters in python and the program then goes through all the possible combinations of those letters. Then it compares that to check if it is in the dictionary or is a word. If it is, it gets appended to a list that will be printed out at the end. I had to look up how to do certain things and was doing great until I got this error. I can't find any forum that has this message. Can someone help me and tell me what I need to do to get it to work? Here is my code.

import itertools
import enchant
how_many_letters=True
letters=[]
possible_words=[]
d = enchant.Dict("en_US")
print("Welcome to combination letters helper!")
print("Type the word 'stop' to quit entering letters, other wise do it one at a time.")
while how_many_letters==True:
    get_letters=input("Enter the letters you have with not counting spaces:")
    if get_letters=='stop':
        how_many_letters=False
    letters.append(get_letters)
length=len(letters)
length=length-1
del letters[length:]
print(letters)
for i in range(length):
  for subset in itertools.combinations(letters, i):#Subset is the combination thing
    print(subset)
    check=d.check(subset)
    print(check)
    if check==True:
        possible_words.append(check)
print(possible_words)

Thanks in advance.

Upvotes: 1

Views: 591

Answers (1)

Dan-Dev
Dan-Dev

Reputation: 9430

The answer to you question is this:

for i in range(1, length + 1):
  for subset in itertools.combinations(letters, i):#Subset is the combination thing
    s = ''.join(subset)
    print(s)
    check=d.check(s)
    print(check)
    if check==True:
        possible_words.append(s)
print(possible_words)

You need to pass enchant a string not a tuple and your range was not working.

(It's possible you may want to look at itertools.permutations(), I don't know if that is what you want though.)

Upvotes: 2

Related Questions