def hamming (a,b): return map(lambda x,y: x==y and 1 or 0, a,b).count(1) a=(0,1,0,1,0,1,1,1,0,1) b=(1,0,0,1,0,0,1,1,1,0) print hamming(a,b) # 5 --------------------------------------- def horner (a,x): b=0 for ak in a: b=b*x+ak return b --------------------------------------- def sommacoseni (a,x): a.reverse(); ix=x*1j z1=cmath.exp(ix); z2=cmath.exp(-ix) return (horner(a,z1)+horner(a,z2))/2 a=[2,3,0,4,7,1,3] print sommacoseni(a,0.2) # (14.7458647279+0j)