We are given a sequence of coplanar points and see all the possible triangles that may be generated which all combinations of three points.
We have the following list of points with the cartesian coordinates of each one:
```
Points [x, y]
   A   [1, 2]
   B   [3, 3]
   C   [4, 1]
   D   [1, 1]
   E   [4, -1]
```
With these points we may have the following triangles: ```ABC, ABD, ABE, ACD, ACE, ADE, BCD, BCE, BDE, CDE.``` There are three special ones: ```ABC, ACD and CDE```, that have an angle of 90°. All is shown in the picture below:
We need to count all the rectangle triangles that may be formed by a given list of points.
The case decribed above will be:
```python
count_rect_triang([[1, 2],[3, 3],[4, 1],[1, 1],[4, -1]]) == 3
```
Observe this case:
```python
count_rect_triang([[1, 2],[4, -1],[3, 3],[4, -1],[4, 1],[1, 1],[4, -1], [4, -1], [3, 3], [1, 2]]) == 3
```
If no rectangle triangles may be generated the function will output ```0```.
Enjoy it!
from itertools import combinations

def count_rect_triang(points):
    return sum(1
        for ps in combinations(set(map(tuple, points)), 3)
        for p0, p1, p2 in ((ps[0], ps[1], ps[2]), (ps[1], ps[2], ps[0]), (ps[2], ps[1], ps[0]))
        if (p1[0]-p0[0])*(p2[0]-p0[0]) + (p1[1]-p0[1])*(p2[1]-p0[1]) == 0)
from itertools import combinations

def count_rect_triang(points):
    return sum(1
        for ps in combinations(set(map(tuple, points)), 3)
        for p0, p1, p2 in ((ps[0], ps[1], ps[2]), (ps[1], ps[2], ps[0]), (ps[2], ps[1], ps[0]))
        if (p1[0]-p0[0])*(p2[0]-p0[0]) + (p1[1]-p0[1])*(p2[1]-p0[1]) == 0)