Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Python Sequences Sequence Iteration Iterating with Enumerate

Isn't enumerate a very inefficient way to get a simple loop counter? What if you're using a large dataset 10,000 times?

It just seems that calling a function during each loop iteration (a function that returns an object, no less) is too much when you could store a local variable and increment it?

1 Answer

Travis Alstrand
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Travis Alstrand
Treehouse Teacher

Hey cassidyb ! :smiley:

To be honest, I haven't built anything using numbers like this yet so I started Googling :smile:

According to this Geeks for Geeks page, it's just adding a counter to an iterable.

According to this python-reference page, it's returning an enumerate object like you said.

This article has some alternatives if you find yourself in this situation and performance does in fact start getting noticeably worse. :smiley: