The problem is here:
for x in alist:
for y in blist:
, alist blist. , alist = [1, 2, 3] blist = [4, 5, 6] (1, 4), (1, 5), (1, 6), (2, 4), (2, 5), (2, 6), (3, 4), (3, 5), (3, 6). , , - (1, 4), (2, 5), (3, 6). zip. zip(alist, blist), . ,
list(zip(alist, blist))
Out: [(1, 4), (2, 5), (3, 6)]
, zip, .
def distance(alist, blist):
sum_of = 0
for x, y in zip(alist, blist):
ans = (x - y)**2
sum_of += ans
return (sum_of)**(1/2)
distance([1, 1, 3], [2, 2, 3])
Out: 1.4142135623730951