Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Convert Tuple to List in Python
Next article icon

Use enumerate() and zip() together in Python

Last Updated : 25 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In Python, zip() combines multiple iterables into tuples, pairing elements at the same index, while enumerate() adds a counter to an iterable, allowing us to track the index. By combining both, we can iterate over multiple sequences simultaneously while keeping track of the index, which is useful when we need both the elements and their positions. For Example:

Python
a = [10, 20, 30] b = ['a', 'b', 'c']  for idx, (num, char) in enumerate(zip(a,b), start=1):     print(idx, num, char) 

Output
1 10 a 2 20 b 3 30 c 

Explanation: Loop prints the index (starting from 1) along with the corresponding elements from lists a and b. zip() pairs the elements and enumerate() tracks the index starting from 1.

Syntax of enumerate() and zip() together

for var1,var2,.,var n in enumerate(zip(list1,list2,..,list n))

Parameters:

  • zip(list1, list2, …, list_n) combines multiple iterables element-wise into tuples.
  • enumerate(iterable, start=0) adds an index (starting from start, default is 0) to the tuples.
  • var1, var2, …, var_n variables to unpack the indexed tuple.

Examples

Example 1: Iterating over multiple lists

Python
a = ['sravan', 'bobby', 'ojaswi', 'rohith', 'gnanesh'] b = ['java', 'python', 'R', 'cpp', 'bigdata'] c = [78, 100, 97, 89, 80]  for i, (name, subject, mark) in enumerate(zip(a, b, c)):     print(i, name, subject, mark) 

Output
0 sravan java 78 1 bobby python 100 2 ojaswi R 97 3 rohith cpp 89 4 gnanesh bigdata 80 

Explanation: zip() pairs elements from a, b and c into tuples, while enumerate() adds an index. The loop extracts and prints i, name, subject and mark.

Example 2: Storing the tuple output

Python
a = ['sravan', 'bobby', 'ojaswi', 'rohith', 'gnanesh'] b = ['java', 'python', 'R', 'cpp', 'bigdata'] c = [78, 100, 97, 89, 80]  for i, t in enumerate(zip(a,b,c)):     print(i, t) 

Output
0 ('sravan', 'java', 78) 1 ('bobby', 'python', 100) 2 ('ojaswi', 'R', 97) 3 ('rohith', 'cpp', 89) 4 ('gnanesh', 'bigdata', 80) 

Explanation: zip() pairs elements from a, b and c into tuples, while enumerate() adds an index. The loop extracts and prints i and the tuple t containing name, subject and mark.

Example 3: Accessing Tuple Elements Using Indexing

Python
a = ['sravan', 'bobby', 'ojaswi', 'rohith', 'gnanesh'] b = ['java', 'python', 'R', 'cpp', 'bigdata'] c = [78, 100, 97, 89, 80]  for i, t in enumerate(zip(a,b,c)):     print(i, t[0], t[1], t[2]) 

Output
0 sravan java 78 1 bobby python 100 2 ojaswi R 97 3 rohith cpp 89 4 gnanesh bigdata 80 

Explanation: zip() pairs elements from a, b and c into tuples, while enumerate() adds an index. The loop extracts and prints i, t[0] (name), t[1] (subject) and t[2] (mark) from each tuple.

Related Articles:

  • Enumerate() in Python
  • zip() in Python
  • Tuple Operations in Python
  • Python Tutorial


Next Article
Convert Tuple to List in Python
author
sravankumar_171fa07058
Improve
Article Tags :
  • Python
  • Python-Functions
Practice Tags :
  • python
  • python-functions

Similar Reads

  • Enumerate() in Python
    enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list(). Let's look at a simple exa
    3 min read
  • What Does the Enumerate Function in Python do?
    The enumerate function in Python is a built-in function that allows programmers to loop over something and have an automatic counter. It adds a counter to an iterable and returns it as an enumerate object. This feature is particularly useful when you need not only the values from an iterable but als
    2 min read
  • Iterate over a tuple in Python
    Python provides several ways to iterate over tuples. The simplest and the most common way to iterate over a tuple is to use a for loop. Below is an example on how to iterate over a tuple using a for loop. [GFGTABS] Python t = ('red', 'green', 'blue', 'yellow') # itera
    2 min read
  • Convert Tuple to List in Python
    In Python, tuples and lists are commonly used data structures, but they have different properties: Tuples are immutable: their elements cannot be changed after creation.Lists are mutable: they support adding, removing, or changing elements.Sometimes, you may need to convert a tuple to a list for fur
    2 min read
  • Create a List of Tuples in Python
    The task of creating a list of tuples in Python involves combining or transforming multiple data elements into a sequence of tuples within a list. Tuples are immutable, making them useful when storing fixed pairs or groups of values, while lists offer flexibility for dynamic collections. For example
    3 min read
  • How to iterate through list of tuples in Python
    In Python, a list of tuples is a common data structure used to store paired or grouped data. Iterating through this type of list involves accessing each tuple one by one and sometimes the elements within the tuple. Python provides several efficient and versatile ways to do this. Let’s explore these
    2 min read
  • Working with zip files in Python
    This article explains how one can perform various operations on a zip file using a simple python program. What is a zip file? ZIP is an archive file format that supports lossless data compression. By lossless compression, we mean that the compression algorithm allows the original data to be perfectl
    5 min read
  • JavaScript Equivalent to Python zip
    In Python, we use zip() function to combine multiple iterables like lists into pairs or tuples. This is really helpful when we want to loop through two or more lists at the same time. [GFGTABS] Python a = [1, 2, 3] b = ['a', 'b', 'c'] result = zip(a, b) print(list(result)) [/
    3 min read
  • How to add Elements to a List in Python
    In Python, lists are dynamic which means that they allow further adding elements unlike many other languages. In this article, we are going to explore different methods to add elements in a list. For example, let's add an element in the list using append() method: [GFGTABS] Python a = [1, 2, 3] a.ap
    2 min read
  • How to Concatenate Two Lists Index Wise in Python
    Concatenating two lists index-wise means combining corresponding elements from both lists into a single element, typically a string, at each index . For example, given two lists like a = ["gf", "i", "be"] and b = ["g", "s", "st"], the task is to concatenate each element from a with the corresponding
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences