def radix_sort(k, arr, base=2):
  """
  Radix sort for an arbitrary base
  Sorts a list of integers in [0, k)

  """
  i = 0
  while (base ** i) < k:
    buckets = [[] for j in range(base)]
    for key in arr:
      digit = (key // (base ** i)) % base
      buckets[digit].append(key)
    arr = []
    for j in range(base):
      for key in buckets[j]:
        arr.append(key)
    i += 1
  return arr