How can I optimize this Python code to generate all words with word-distance 1?

前端 未结 12 1032
予麋鹿
予麋鹿 2021-01-30 22:11

Profiling shows this is the slowest segment of my code for a little word game I wrote:

def distance(word1, word2):
    difference = 0
    for i in range(len(word         


        
12条回答
  •  无人共我
    2021-01-30 22:35

    For such a simple function that has such a large performance implication, I would probably make a C library and call it using ctypes. One of reddit's founders claims they made the website 2x as fast using this technique.

    You can also use psyco on this function, but beware that it can eat up a lot of memory.

提交回复
热议问题