import random def get_values(lower_bound, upper_bound, number_of_points): return [random.randint(lower_bound,upper_bound) for i in range(number_of_points)] def compare(point_one, point_two): if point_one[0] == point_two[0]: return cmp(point_one[1], point_two[1]) else: return cmp(point_one[0], point_two[0]) def main(): number_of_points = 20 lower_bound = 0 upper_bound = 10 points = [(x,y) for (x,y) in zip(get_values(lower_bound, upper_bound, number_of_points), get_values(lower_bound, upper_bound, number_of_points))] ordered = sorted(points, compare) print(ordered) main()
Standard input is empty
[(0, 6), (0, 9), (1, 8), (1, 8), (2, 4), (2, 7), (2, 9), (4, 7), (4, 8), (5, 1), (5, 6), (7, 10), (8, 8), (8, 8), (9, 2), (9, 3), (9, 4), (9, 9), (10, 3), (10, 3)]