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
for this snippet:
for x,y in zip (word1, word2): if x != y: difference += 1 return difference
i'd use this one:
return sum(1 for i in xrange(len(word1)) if word1[i] == word2[i])
the same pattern would follow all around the provided code...