def sorting(list, key):
for i in range(len(list)):
for j in range(i, len(list)):
if key(list[i]) > key(list[j]):
list[i], list[j] = list[j], list[i]
def size(int_type):
length = 0
count = 0
while (int_type):
count += (int_type & 1)
length += 1
int_type >>= 1
return count
arr = [5,4,3,1,6,8,10,9]
sorting(arr, lambda x : size(x))
print(arr)
#https://pt.stackoverflow.com/q/347634/101
ZGVmIHNvcnRpbmcobGlzdCwga2V5KToKICAgIGZvciBpIGluIHJhbmdlKGxlbihsaXN0KSk6CiAgICAgICAgZm9yIGogaW4gcmFuZ2UoaSwgbGVuKGxpc3QpKToKICAgICAgICAgICAgaWYga2V5KGxpc3RbaV0pID4ga2V5KGxpc3Rbal0pOgogICAgICAgICAgICAgICAgbGlzdFtpXSwgbGlzdFtqXSA9IGxpc3Rbal0sIGxpc3RbaV0KZGVmIHNpemUoaW50X3R5cGUpOgogICBsZW5ndGggPSAwCiAgIGNvdW50ID0gMAogICB3aGlsZSAoaW50X3R5cGUpOgogICAgICAgY291bnQgKz0gKGludF90eXBlICYgMSkKICAgICAgIGxlbmd0aCArPSAxCiAgICAgICBpbnRfdHlwZSA+Pj0gMQogICByZXR1cm4gY291bnQKYXJyID0gWzUsNCwzLDEsNiw4LDEwLDldCnNvcnRpbmcoYXJyLCBsYW1iZGEgeCA6IHNpemUoeCkpCnByaW50KGFycikKCiNodHRwczovL3B0LnN0YWNrb3ZlcmZsb3cuY29tL3EvMzQ3NjM0LzEwMQ==