Skip to main content

If I remember correctly, I answered a similar question yesterday Finding the given word from jumbled letters

Basically, doing permutations is going to take too long: a double for loop results in a complexity of \$O(n²)\$.

As suggested in the link, use sorting and scan linear if the output is correct or use the second approach described by thepace, which runs in \$O(n)\$

Perhaps you could run through the word file and try each word with one of the above approaches. (I believe this will run faster)

Regarding to your python code, may I suggest to use a main() function (http://stackoverflow.com/questions/4041238/why-use-def-main) and call it by using:

if __name__ == "__main__":
   main()

This is a common convention and splits your main code and your other functions in a clear way. It also prevents the code being run while it's included as a module.

goodluck!

DJanssens
  • 1.5k
  • 1
  • 15
  • 27