Question: I need to sum from `i=1 to n` over `(y_i-A-B*x_i)^2`.

A and B are fixed constants. y\_i and x\_i are the elements of two lists.

I tried it with `sum([m-A-B*n for m,n in zip(Tlog_dist,Tlog_Tb)])` but I think then over all posible pairs of numbers is summed, not just the i'th with the i'th. 

I looked around and saw some stuff with a for loop and enumerate but got stuck because I'm new and never worked with a loop before.

Answer: 
Use `numpy` for a vectorised solution.

```
import numpy  as np

A = 5
B = 7
y = np.array([1, 2, 3, 4, 5])
x = np.array([6, 7, 8, 9, 10])

# (y_i-A-B*x_i)^2
res = np.sum((y - A - B*x)**2)

```

A list-based solution is possible, but not recommended.
```
def calsum(n,list1,list2,A,B):
        returnvalue=0
        if n <= len(list1):
                for i in range(n):
                        sumvalue=list2[i]-A-B*list1[i]
                        power=sumvalue ** 2
                        returnvalue += power
        else:
                print "Sum is not posible with given n value"
        return returnvalue

list1=[1,2,3,4,5]
list2=[6,7,8,9,10]

if len(list1) == len(list2):
        print"Length matched"
#       calsum(n,list1,list2,A,B)
        result=calsum(5,list1,list2,1,1)
        print result
else:
        print"Not in same length"

```