I realize that Python isn't the most performant language, but since this seems like it would be easy, I'm wondering whether it's worthwhile to move a range assignment outside of a for loop if I have nested loops. For example:
for i in range(1000):
for j in range(1000):
foo()
versus
r = range(1000)
for i in range(1000):
for j in r:
foo()
Will the second one run faster, or will the Python interpreter optimize out the repeated function call in the first example? Also, does the answer change if I were to use xrange? (or Python 3 range). Thanks!