Geek Culture
Published in

Geek Culture

Ditch loop counters, use this instead

Write more pythonic code with enumerate

Even though it is often best to avoid loop counters, there are times when they can be useful.

Fortunately, you don’t have to forget everything you have learnt so far — you can use the enumerate function. This gives us access to the loop count within a Pythonic for loop.

Enumerating a list

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Martin McBride

Martin McBride

Software developer. Java, Python, C++ etc. I write for pythoninformer.com and maintain the generativepy library.