How can this Python Scrabble word finder be made faster?

前端 未结 5 842
梦如初夏
梦如初夏 2021-01-31 10:08

I have no real need to improve it, it\'s just for fun. Right now it\'s taking about a second on a list of about 200K words.

I\'ve tried to optimize it as much as I know

5条回答
  •  猫巷女王i
    2021-01-31 10:33

    You can use the fact the /usr/dict/share/words dictionary is sorted to allow you to skip a lot of words in the dictionary without considering them at all.

    For instance, suppose a dictionary word starts with "A" and you don't have "A" in the rack. You can do a binary search on the word list for the first word which starts with a "B" and skip all the words inbetween. This will make a big difference in most cases - you'll skip maybe half the words.

提交回复
热议问题