How do you convert a c-style for loop into python?
for (int i = m; i >= lowest; i--)
The best that I came up with was:
i = mid
for i in range(i, low,-1):
for i in range(m, low - 1, -1):
Keep in mind range is exclusive of the stop parameter.
range(...)
range(stop) -> list of integers
range(start, stop[, step]) -> list of integers
The difference between this code and the C code is that in Python 2, a list is being constructed in memory by range so for very huge ranges this could be a problem. Replacing range with xrange would not build a list in memory and make the code practically the same. In Python 3 this issue no longer exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With