Hamming Distance

Raymond Hettinger python at rcn.com
Fri Jun 20 03:10:23 CEST 2008


Non-recursive, 8-bit block table lookup version:

def ham(a, b, ht=[hamdist(a,0) for a in range(256)]):
    x = a ^ b
    dist = 0
    while x:
        dist += ht[x & 255]
        x >>= 8
    return dist

Raymond





More information about the Python-list mailing list