Returning all possible English dictionary words that can be formed out of a string I am using an external library named enchant here. My problem is that I guess my program is not returning all possible English words and is slow as well for large string input.

I am using both en_US and en_UK here:

import enchant
import itertools
uk = enchant.Dict("en_UK")
us=enchant.Dict("en_US")
a=[] # stores all possible string combinations
ent=input('enter the word: ')
ent=ent.rstrip('\r\n')
i=3 # minimum length of words
while i&lt;=len(ent):
  it=itertools.permutations(ent,i)
  for y in it:
    a.append("".join(y))
  i+=1 
a.sort(key=len,reverse=True)
possible_words=[]
for x in a:
  if uk.check(x) and x not in possible_words :
    possible_words.append(x) 

for x in a :
  if us.check(x) and x not in possible_words:
    possible_words.append(x)

possible_words.sort(key=len,reverse=True)
for x in possible_words:
  print(x)


Example :

enter the word: wsadfgh
wash
wads
wags
swag
shag
dash
fads
fags
gash
gads
haws
hags
shaw
shad
was
wad
wag
saw
sad
sag
ash
ads
fwd
fas
fad
fag
gas
gad
haw
has
had
hag
As a general advice, you may want to organize your code into functions - say


One function to receive user input and process it
One function to generate all possible permutations for a string passed in less than a value (here 3).
Another function to filter this based on whether the string passed in is in us or uk dictionaries
At the end, you can combine these as a list comprehension.


Regarding your problem of performance, time the program with the itertools permutation output alone (without dict checking). My guess would be that the permutations is taking the time, but it would be nice to verify. 

You may also want to check where the valid words are getting filtered. (Since you say that not all the words are being output). My guess is that permutation produces them but is not present in the enchant dictionary. But please verify.
Here is a possible rewriting of your code. It removes the redundant sorts

import enchant
import itertools

MIN_LEN = 3
uk = enchant.Dict("en_UK")
us = enchant.Dict("en_US")

def get_input():
  return sorted(set(input('enter the word: ').rstrip('\r\n')))

def gen_permutations(ent):
  tuples = map(lambda i: itertools.permutations(ent,i), range(MIN_LEN,len(ent)+1))
  arrr= [["".join(j) for j in i] for i in tuples]
  return list(itertools.chain(*arrr))

def filter_dict(words):
  return [x for x in words if uk.check(x) or us.check(x)]

for i in filter_dict(gen_permutations(get_input())):
  print i