Skip to content
Advertisement

How to implement this for loop in Python

Im trying to implement Radix Sort in Python. In the main Radix Sort function there is a for loop like this:

JavaScript

i did implement it using a while loop like below:

JavaScript

But since for loop is faster than while loop, I wonder how to implement that pseudocode in Python with a for loop. Any suggestions?

Note: Radix Sort uses counting sort to sort based on digits starting from the right most digit (p=1) to the last digit and that’s why for loop is used.

Advertisement

Answer

Well after doing a research on the loops topic, i found that using a string instead of doing calculation is much faster. It is not the correct answer but it is the fastest implementation in Python.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement