The least significant digit radix sort algorithm takes each number in the input list, looks at the digits of that number in order from right to left, and incrementally stuffs each number into the bucket corresponding to the value of that digit.
First we’re going to write this logic for the least significant digit, then we’re going to loop over the code we write to do that for every digit.
We’ll need to iterate over
being_sorted. Grab each value of
being_sorted and save it as the temporary variable
number to a string and save that as
How do we get the last element of a string? This would correspond to the least significant digit of the number. For strings, this is simple, we can use a negative index.
Save the last element of
number_as_a_string to the variable
Now that we have a string containing the least significant digit of
number saved to the variable
digit. We want to use
digit as a list index for
digits. Unfortunately, it needs to be an integer to do that. But that should be easy for us to do:
digit equal to the integer form of
We know that
digits[digit] is an empty list (because
digits has ten lists and
digit is a number from 0 to 9). So let’s add our number to that list!
digits[digit] with the argument
Now break out of the for loop and return