listing implementation of the radix sort using an array of queues sorts sequence of positive integers using the radix sort algorithm from llistqueue import queue from array import array def radixsortintlistnumdigits )create an array of queues to represent the bins binarray array for in range )binarray[kqueue(the value of the current column column iterate over the number of digits in the largest value for in rangenumdigits )distribute the keys across the bins for key in intlist digit (key /column binarray[digitenqueuekey gather the keys from the bins and place them back in intlist for bin in binarray while not bin isempty(intlist[ibin dequeue( + advance to the next column value column * the ten-element arraythe distribution is easily handled by determining the bin or corresponding queue to which each key has to be added (based on the digit in the current column being processedand enqueuing it in that queue to extract the individual digitswe can use the following arithmetic expressiondigit (key /columnvalue where column is the value ( of the current column being processed the variable is initialized to since we work from the least-significant digit to the most significant after distributing the keys and then gathering them back into the sequencewe can advance to the next column by simply multiplying the current value by as is done at the bottom of the outer loop in line the second nested loopin lines - handles the gathering step to remove the keys from the queues and place them back into the sequencewe must dequeue all of the keys from each of the ten queues and add them to the sequence in successive elements starting at index position zero