fork download
  1. def sorting(list, key):
  2. for i in range(len(list)):
  3. for j in range(i, len(list)):
  4. if key(list[i]) > key(list[j]):
  5. list[i], list[j] = list[j], list[i]
  6. def size(int_type):
  7. length = 0
  8. count = 0
  9. while (int_type):
  10. count += (int_type & 1)
  11. length += 1
  12. int_type >>= 1
  13. return count
  14. arr = [5,4,3,1,6,8,10,9]
  15. sorting(arr, lambda x : size(x))
  16. print(arr)
  17.  
  18. #https://pt.stackoverflow.com/q/347634/101
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
[4, 1, 8, 5, 6, 3, 10, 9]