how to refactor nested for loop into smaller for loop assume each of them independent?

Chris Angelico rosuav at gmail.com
Sat Oct 8 06:03:43 EDT 2016


On Sat, Oct 8, 2016 at 8:58 PM, meInvent bbird <jobmattcon at gmail.com> wrote:
> how to refactor nested for loop into smaller for loop assume each of them independent?
>
> because memory is not enough
>
> for ii in range(1,2000):
>  for jj in range(1,2000):
>   for kk in range(1,2000):
>     print run(ii,jj,kk)

Since you're using Python 2, you could try xrange instead of range.
But it won't make a lot of difference. You're trying to call your run
function 8,000,000,000 times... that is a *lot* of function calls.
Consider a faster algorithm instead!

ChrisA



More information about the Python-list mailing list