Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Python

    Adding backend to CodePen snippet using Python/Django | Question-Answering Application

    Beginners

    Build Real-world React Native App #0: Overview & Requirement

    Medical Marketing

    Analyzing Emerging Trends in Health and Medical Marketing

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Friday, February 6
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / Python / Python enumerate() Explained and Visualized
    Programming

    Python enumerate() Explained and Visualized

    Denis KryukovBy Denis KryukovSeptember 13, 2019Updated:December 6, 2024No Comments7 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Python enumerate() Explained and Visualized
    Explaining Python 3, episode 1
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    artwork depicting a stylized Python 3 enumerate() function
    Explaining Python 3, episode 1

    Python is the favorite programming language of many developers; contrary to popular belief, it isn’t merely a “technology for newbies” — its power and functionality make it an excellent tool for a plethora of tasks (our Python interview questions prove it quite well)

    Python is renowned for its collection of libraries, modules, and functions that it comes packaged with — and enumerate() is something many developers want to understand better. In this article, we’ll explore what enumerate() actually is, analyze its functionality, and highlight how you should use it to maximize its efficiency and performance. Read enough of our articles — and you might be able to join our platform and find great remote projects to work on! 😉

    We’ve noticed that other articles covering this topic use Python 2 for some reason — the code in this article is from Python 3.

    OK, so what does enumerate() do?

    In many situations, we need to get the element’s index while iterating over an iterable element (i.e. any object that we can loop over). One way to achieve the desired result would be this:

    animals = ['dog', 'cat', 'mouse']
    for i in range(len(animals)):
        print(i, animals[i])
    

    which will result in:

    0 dog
    1 cat
    2 mouse
    

    Most developers coming from a C++/Java background will probably opt for the implementation above — iterating over the iterable’s length via the index is a familiar concept for them. The problem with this approach, however, is its inefficiency. enumerate() is the right way to do things:

    for i, j in enumerate(example):
        print(i, j)
    

    As revealed by Python’s in-built help() module, The enumerate object yields pairs containing a count (from start, which defaults to zero) and a value yielded by the iterable argument. Another description can be found in Allen B. Downey’s excellent Think Python book: The result from enumerate is an enumerate object, which iterates a sequence of pairs; each pair contains an index (starting from 0) and an element from the given sequence.

    enumerate() offers a great functionality — for instance, it comes in handy when you need to obtain an indexed list:

    (0, seq[0]), (1, seq[1]), (2, seq[2]), ...

    Case study 1: Enumerate a string

    artwork depicting how to enumerate a string
    A string is just a list, metaphorically speaking

    To understand string enumeration better, we can imagine our given string as a collection of individual characters (items). Therefore, enumerating over a string will give us:

    1. The character’s index.
    2. The character’s value.
    word = "Speed"
    for index, char in enumerate(word):
        print(f"The index is '{index}' and the character value is '{char}'")
    

    And here’s the output:

    The index is '0' and the character value is 'S'
    The index is '1' and the character value is 'p'
    The index is '2' and the character value is 'e'
    The index is '3' and the character value is 'e'
    The index is '4' and the character value is 'd'
    

    Case study 2: Enumerate a list

    artwork depicting how to enumerate a list
    So how should we go about enumerating a list?..

    The next logical step is enumerating a list. In order to do this, we can utilize a for loop and iterate over each item’s index and value:

    sports = ['soccer', 'basketball', 'tennis']
    for index, value in enumerate(sports):
        print(f"The item's index is {index} and its value is '{value}'")
    

    The output will be:

    The item's index is 0 and its value is 'soccer'
    The item's index is 1 and its value is 'basketball'
    The item's index is 2 and its value is 'tennis'
    

    Case study 3: Customizing the starting index

    artwork depicting how to change the enumeration starting position
    Starting index can be changed

    We can see that enumeration begins at the index 0; however, we often need to change the starting position to allow for more customizability. Thankfully, enumerate() also takes an optional argument [start]

    enumerate(iterable, start=0)

    which can be used to indicate the index start position. Here’s how you can implement it:

    students = ['John', 'Jane', 'J-Bot 137']
    for index, item in enumerate(students, start=1):
        print(f"The index is {index} and the list element is '{item}'")
    

    This gives us…

    The index is 1 and the list element is 'John'
    The index is 2 and the list element is 'Jane'
    The index is 3 and the list element is 'J-Bot 137'
    

    Now let’s edit the code a bit – you’ll see that:

    • The starting index can be negative.
    • You can omit start= and simply pass the integer argument without it.
    teachers = ['Mary', 'Mark', 'Merlin']
    for index, item in enumerate(teachers, -5):
        print(f"The index is {index} and the list element is '{item}'")
    

    The output will be:

    The index is -5 and the list element is 'Mary'
    The index is -4 and the list element is 'Mark'
    The index is -3 and the list element is 'Merlin'
    

    Case study 4: Enumerate a tuple

    Working with tuples follows the same logic as list enumeration:

    colors = ('red', 'green', 'blue')
    for index, value in enumerate(colors):
        print(f"The item's index is {index} and its value is '{value}'")
    

    The output:

    The item's index is 0 and its value is 'red'
    The item's index is 1 and its value is 'green'
    The item's index is 2 and its value is 'blue'
    

    Case study 5: Enumerate a list of tuples

    artwork depicting a set of Python 3 tuples inside a list
    Tuples in lists, in tuples, in lists, in…

    Let’s take it up a notch and combine a number of tuples into a list… and now we want to enumerate this list of tuples. One option would be writing code like this:

    letters = [('a', 'A'), ('b', 'B'), ('c', 'C')]
    for index, value in enumerate(letters):
        lowercase = value[0]
        uppercase = value[1]
        print(f"Index '{index}' refers to the letters '{lowercase}' and '{uppercase}'")
    

    However, tuple unpacking proves to be a more efficient approach. Here’s an example:

    letters = [('a', 'A'), ('b', 'B'), ('c', 'C')]
    for i, (lowercase, uppercase) in enumerate(letters):
        print(f"Index '{i}' refers to the letters '{lowercase}' and '{uppercase}'")
    

    This will output:

    Index '0' refers to the letters 'a' and 'A'
    Index '1' refers to the letters 'b' and 'B'
    Index '2' refers to the letters 'c' and 'C'
    

    Case study 6: Enumerate a dictionary

    artwork depicting how to enumerate a dictionary
    The English — Integer Dictionary

    It may seem that enumerating a dictionary would be similar to enumerating a string or a list — but it’s not. The main difference associated with dictionaries is their order structure, i.e. the way the elements are ordered in this particular data structure. Dictionaries are somewhat arbitrary because the order of their items is unpredictable. If we create a dictionary and print it, we’ll get one order:

    translation = {'one': 'uno', 'two': 'dos', 'three': 'tres'}
    print(translation)
    # Output on our computer: {'one': 'uno', 'two': 'dos', 'three': 'tres'}

    However, if you print this very dictionary, the order might be different!

    Read More:  Comprehension in Python

    As dictionary items cannot be accessed by indices, we’ll have to utilize the for loop to iterate over the dictionary’s keys and values. The key — value pair is called an item, so we’ll use the .items() method for this purpose:

    animals = {'cat': 3, 'dog': 6, 'bird': 9}
    for key, value in animals.items():
        print(key, value)
    

    The output will be:

    cat 3
    dog 6
    bird 9
    

    Conclusion

    We’ve got numerous other Python 3 functions, libraries, and modules to cover in the future — stay tuned! 🙂

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Denis Kryukov
    • Website

    Related Posts

    Mastering REST APIs: Essential Techniques for Programmers

    December 18, 2024

    Crafting Interactive User Interfaces Using JavaScript Techniques

    December 17, 2024

    Effective Strategies for Utilizing Frameworks in Web Development

    December 16, 2024
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    JavaScript October 4, 2019

    JSON WEB Authentication with Angular 8 and NodeJS

    The article is about interfacing an Angular 8 Project with a secure backend API. The Backend will be running on Node.JS. The security that will underlay the interfacing will be JSON Web Tokens. 

    DevOps Overview: Rethinking How Development and Operations Work

    August 26, 2019

    Broad Topics in Tech Podcasts — Part 4

    April 22, 2019

    Creating Mock API using Mirage in a React application

    August 12, 2020

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    Programming Patterns. Publisher/Subscriber, Mediator

    Programming March 7, 2017

    Advanced Node.Js: A Hands on Guide to Event Loop, Child Process and Worker Threads in Node.Js

    JavaScript January 24, 2020

    Strategies for Overcoming Recruitment Challenges in 2023

    Recruitment December 4, 2024

    Tips and Tricks for a Newbie at Web Development: How to Prepare for the Interview

    Interview December 10, 2019

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    LinkedIn

    Effective LinkedIn Messaging Strategies to Qualify Prospects

    Interview

    Interview with Max

    Programming

    Short React Story

    Most Popular

    How to Take Control of Your Tech Interview | Take Charge in Three Easy Steps

    Interview

    Build Real-World React Native App #11 : Pay For Remove Ads

    JavaScript

    3 Proven Strategies to Find Work-Life Balance for Remote Workers

    Job
    © 2026 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.