Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eder-projetos-dev/610e9e52702af4065c1fa944c006a389 to your computer and use it in GitHub Desktop.
Save eder-projetos-dev/610e9e52702af4065c1fa944c006a389 to your computer and use it in GitHub Desktop.
Python - Enumerate
fruits = ['apple', 'banana', 'orange']
for index, fruit in enumerate(fruits):
print(f"Index: {index}, Fruit: {fruit}")
@eder-projetos-dev
Copy link
Author

Enumerate

I think enumerate() is a handy function when I need to iterate over a list and also access the index of each element. It eliminates the need for maintaining a separate counter variable and improves code readability. For instance, I can use enumerate() to iterate over a list of fruits and print both the index and the fruit name.

https://levelup.gitconnected.com/11-tricks-that-will-make-your-life-easier-as-a-python-developer-da29e4306675

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment