Isabella Hope
- 2
- 0
- TL;DR
- Noticing slower execution when looping through larger Python lists. Wondering if this is normal behavior or if I’m misunderstanding how Python handles iteration internally.
Hi everyone,
I’m practicing Python and noticed something strange.
When I run a simple loop on a small list, it’s fast—but when I run the same loop on a much larger list, the execution time increases more than I expected.
Example (simplified version):
My question:
Is this slowdown normal due to the size of the list, or is there something about Python’s loop execution that I might be misunderstanding?
I’m just trying to learn more about how Python handles iteration under the hood.
Any explanation would be appreciated.
Thanks!
Mentor note: cleaned up pasted code removing numerous span tags.
I’m practicing Python and noticed something strange.
When I run a simple loop on a small list, it’s fast—but when I run the same loop on a much larger list, the execution time increases more than I expected.
Example (simplified version):
Python:
data =list(range(1_000_000))
count = 0 for i in data:
count += i
My question:
Is this slowdown normal due to the size of the list, or is there something about Python’s loop execution that I might be misunderstanding?
I’m just trying to learn more about how Python handles iteration under the hood.
Any explanation would be appreciated.
Thanks!
Mentor note: cleaned up pasted code removing numerous span tags.
Last edited by a moderator: