DEV Community

Discussion on: 3 Common Mistakes that Python Newbies Make

Collapse
 
kungtotte profile image
Thomas Landin

enumerate is a great tool and it's what you should use when you actually need the index for something, but most of the time people don't really need the index.

And there's a better way to use it:

for index, value in enumerate(foo):
    # voilà, the values are already unpacked
    # into two handy variables!