fork download
  1. import collections
  2. import math
  3.  
  4. def cmpr(a, b):
  5. print(a, b)
  6. if a[0]/r != b[0]/r:
  7. return a[0]/r < b[0]/r
  8. return a[1] < b[1]
  9.  
  10. a = [1, 1, 2, 1, 3, 4, 5, 2, 8];
  11. r = math.sqrt(len(a))
  12. d_query = {0:[0, 4], 1:[5, 7], 2:[2, 4], 3:[5, 8]}
  13. od = collections.OrderedDict(sorted(d_query.items(), cmpr, key= lambda x: x[1]))
Success #stdin #stdout 0s 23688KB
stdin
Standard input is empty
stdout
([5, 7], [0, 4])
([2, 4], [5, 7])
([5, 8], [2, 4])