Hamming Distance

Raymond Hettinger python at rcn.com
Thu Jun 19 21:10:23 EDT 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