In this kata you're expected to sort an array of 32-bit integers in ascending order of the number of **on** bits they have.

E.g Given the array **[7, 6, 15, 8]**

- 7 has **3 on** bits  (000...0**111**)
- 6 has **2 on** bits  (000...00**11**)
- 15 has **4 on** bits (000...**1111**)
- 8 has **1 on** bit   (000...**1**000)

So the array in sorted order would be **[8, 6, 7, 15]**.

In cases where two numbers have the same number of bits, compare their real values instead.

E.g between 10 **(...1010)** and 12 **(...1100)**, they both have the same number of **on** bits '**2**' but the integer 10 is less than 12 so it comes first in sorted order.

Your task is to write the function `sortBybit()` that takes an array of integers and sort them as described above.

```if-not:haskell
Note: Your function should modify the input rather than creating a new array.
```

Difficulty: introductory

Starter code:

def sort_by_bit(arr):
	

Solutions:
def sort_by_bit(arr): 
    return sorted(arr, key=lambda x: (bin(x).count("1"), x))

def sort_by_bit(a):
    return sorted(a, key=lambda x: (bin(x).count("1"), x))

def sort_by_bit(arr): 
    return sorted(arr, key=lambda n: (bin(n).count("1"), n))

def sort_by_bit(lst): 
    return sorted(lst, key=lambda n: (f"{n:b}".count("1"), n))


def sort_by_bit(a):
    for i in range(len(a)):
      for j in range(i+1, len(a)):
        if bin(a[i]).count('1') > bin(a[j]).count('1'):
          a[i], a[j] = a[j], a[i]
        elif bin(a[i]).count('1') == bin(a[j]).count('1'):
          if a[i] > a[j]:
            a[i], a[j] = a[j], a[i]
    return a

def sort_by_bit(arr):
    return [val[1] for val in sorted([["{0:b}".format(val).count('1'),val] for val in arr])]

def sort_by_bit(arr):
    return sorted(arr, key=lambda x: (str('{:032b}'.format(x)).count('1'), x))


def sort_by_bit(arr):
    return sorted(sorted(arr), key=lambda i: bin(i)[2:].count('1'))

def sort_by_bit(arr): 
    return sorted(arr, key=lambda x: (count(x), x))
def count(n):
    return bin(n)[2:].count("1")

def sort_by_bit(x): 
    on_bits = [f"{i:b}".count("1") for i in x]
    sorted_tups = sorted(zip(on_bits, x))
    return list(list(zip(*sorted_tups))[1])