**Update:**

1-line solution as suggested by @StefanPochmann

```
def numberOfBoomerangs(self, points):
return sum(
n * (n - 1)
for x1, y1 in points
for n in collections.Counter(
(x1 - x2) ** 2 + (y1 - y2) ** 2
for x2, y2 in points).values())
```

**Old:**

Just for fun:

```
def numberOfBoomerangs(self, points):
dist = lambda (x1, y1, x2, y2): (x1 - x2) ** 2 + (y1 - y2) ** 2
return sum(
n * (n - 1)
for x1, y1 in points
for n in collections.Counter(dist((x1, y1, x2, y2)) for x2, y2 in points).values())
```

Here is a more clear version:

```
def numberOfBoomrangs(self, points):
nums = 0
for x1, y1 in points:
distance = collections.defaultdict(int)
for x2, y2 in points:
dx = abs(x2 - x1)
dy = abs(y2 - y1)
d = dx * dx + dy * dy
distance[d] += 1
nums += sum(n * (n-1) for n in distance.values())
return nums
```