-1
TIL Python's 'simple' for loop is actually one of the slowest ways to iterate in beginner tutorials
I was following along with a beginner course on Udemy and got curious about why my code was taking so long. Found a blog post from a former game developer that tested loop speeds, and Python's for loop with range() was about 40% slower than using enumerate() for the same task. Every tutorial I've seen pushes range() as the default, but it's apparently not great for big data sets. Has anyone else found other beginner 'best practices' that are actually inefficient?
2 comments
Log in to join the discussion
Log In2 Comments
the_ben13h ago
Honestly that blog post changed my mind too, I always assumed range() was the fastest way.
3
the_wesley12h ago
range() still works fine for most stuff honestly, but switching to enumerate() helped my code run way smoother on lists over 10k items. Also found out that using .join() for strings instead of + is a huge speed boost, total game changer for cleaning up data.
3