Okay, so the wording of this question is very hard to say.
However, I have two scripts written in Python 3.5.2:
import time
t0 = time.clock()
def hello():
a = []
for i in range(10000000):
a.append(i)
hello()
t1 = time.clock()
print((t1-t0))
Out: 1.0960211284655088
and
import time
t0 = time.clock()
a = []
for i in range(10000000):
a.append(i)
t1 = time.clock()
print((t1-t0))
Out: 1.432725885821128
The first script runs faster being inside a defined function and then called; however, I don't know why this is and I would like to understand so I can learn to optimize code.
This is a question regarding only this particular aspect of Python 3. I know list comprehensions and map() are much, much faster and more pythonic methods of doing this particular iteration.