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
People are mainly going about this by trying to write a quicker function, but there might be another way..
"distance" is called over 5 million times
Why is this? Perhaps a better way to optimise is to try and reduce the number of calls to distance, rather than shaving milliseconds of distance's execution time. It's impossible to tell without seeing the full script, but optimising a specific function is generally unnecessary.
If that is impossible, perhaps you could write it as a C module?