fork download
  1. import random
  2.  
  3. def get_values(lower_bound, upper_bound, number_of_points):
  4. return [random.randint(lower_bound,upper_bound) for i in range(number_of_points)]
  5.  
  6. def compare(point_one, point_two):
  7. if point_one[0] == point_two[0]:
  8. return cmp(point_one[1], point_two[1])
  9. else:
  10. return cmp(point_one[0], point_two[0])
  11.  
  12. def main():
  13. number_of_points = 20
  14. lower_bound = 0
  15. upper_bound = 10
  16. 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))]
  17. ordered = sorted(points, compare)
  18. print(ordered)
  19.  
  20. main()
Success #stdin #stdout 0.01s 10024KB
stdin
Standard input is empty
stdout
[(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)]