Objective
A named tuple (namedtuple) is a tuple whose fields have names: you access them with p.x instead of p[0], and it is still immutable and sortable.
Instructions
- The first line has the number
nof points; each one is a linex y(integers). - Create
Point = namedtuple("Point", ["x", "y"])withx. Sort the points by their squared distance to the origin (x² + y²) and, if tied, by the tuple itself. ShowPoint(x=3, y=4) 25for each point and at the endFarthest: Point(...).
3
3 4
1 1
-5 0
Point(x=1, y=1) 2
Point(x=-5, y=0) 25
Point(x=3, y=4) 25
Farthest: Point(x=3, y=4)
Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.
Start exercise