Repository where I mostly put random python scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
463 B

  1. def radix_sort(lista):
  2. max_len = max([len(numero) for numero in lista])
  3. padded = list([str(num).rjust(max_len, "0") for num in lista])
  4. for pos in reversed(range(max_len)):
  5. buckets = [list() for x in range(0, 10)]
  6. for num in padded:
  7. bucket = int(num[pos])
  8. buckets[bucket] += [num]
  9. padded = sum(buckets, [])
  10. return padded
  11. if __name__ == "__main__":
  12. print(radix_sort(["13", "105", "10", "150"]))