if k points are at distance d, then boomrang(d) = k * (k - 1) why is this the case?

Update - understood.

Put each point p at the center of boomrang
cmap[k] are number of points at distance k
p at the center leaves two places open in boomrang
cmap[k] * (cmap[k] - 1) = cmap[k] P 2 or cmap[k]!/(cmap[k]-2)!

For each point p we create a hashmap of the form {d : n} where n is the total number of points that are d distance from p. Then we only need to count the number of unique pairs of those n points. The key insight here is that if we have a list of n points [p1, p2, p3, ..., pn] then there are nP2 = (n! / (n-2)!) = n*(n-1) pairs of points that can follow p in order to form a boomerang.

A workable solution is to complete the hashmap and then iterate through and add the number of pairs to boomerangs. However, if you notice that the sum of n consecutive integers = (n*(n-1))/2 we can count the pairs on the run and then multiply by 2 at the end.

Thanks for sharing, very clever solution. Also thanks to @gorokhovsky for the optimization. I tried it and the two optimizations cut the running time from 251ms to 112ms(currently 99.56% 2017-06-28 23:22:56) on my machine.

@StefanPochmann Thanks for your help, and I'm a beginner of Python. I do not understand how to use "for in" like this. Could you pls explain the syntax.
PS:I know use "for...in.." like this:
def numberOfBoomerangs(self, points):
return sum([sum(n*(n-1) for n in collections.Counter([(x1-x2)**2 + (y1-y2)**2
for x2, y2 in points]).values())
for x1, y1 in points])

yes, my counting is probably not as straight forward as it could have been. But the idea is the same, group them by distance to a center point and use the count and the logic outlined to get the result.

class Solution(object):
def numberOfBoomerangs(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
res = 0
for x1, y1 in points:
cnt = {}
for x2,y2 in points:
dist = (x1-x2)**2+(y1-y2)**2
cnt[dist] = cnt.get(dist,0) + 1
for k in cnt:
res += cnt[k]*(cnt[k]-1)
return res

This code accesses count so many times, even when map.get(dis) is zero. I made added a small if else to this code and was able to cut running time by almost half. Your code took 412ms when I submitted and with this if else,its down to 192ms.
New code:

@fiona8957 I think the time measurements might be wrong for Swift. My solution is similar to yours and all the published solutions, but I'm still getting TLE.

In your case, one improvement to try is getting rid of the dictionary.removeAll() call. Instead, just create a new empty dictionary for every iteration through the outer for loop.