The enumerate() function adds sequential numbering to list items by generating tuples of (index, value), while the zip() function pairs elements from multiple lists by position; combining these functions allows simultaneous numbering and pairing of data from multiple lists, with the start parameter enabling custom numbering sequences.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
[Mini-project] Enumerate() and Zip() - Visually Explained
Added:You're a music producer who's just finished an album. Before the album can be released, you need to take some information about each of the tracks and build a finished track list.
Every song numbered and paired with its duration.
The problem is the information you're given sits scattered across four separate Python lists.
One for the main album titles, another for the durations, and two more with the same details for the bonus tracks.
So, how do you turn these four disconnected lists into the finished track list?
That's exactly what we're going to build, one step at a time, using two of Python's handiest tools for working with lists. Enumerate and zip.
If you tried the practice notebook from our enumerate or zip videos, you can check your work as we go.
And if you haven't, we link the notebook we're using in the description.
Okay, let's dive into the code.
As a first step to our final track list, let's output all the song names in the titles list and their numbered positions.
To display these titles, we simply loop over the titles list.
But, that doesn't give us access to the items' positions.
To get those numbers, we wrap the titles list in the enumerate function right in the loop header.
Now, on each iteration of the loop, the enumerate function generates a tuple containing the position and the title.
To capture both these values and use them independently in the loop body, we unpack them into two variables, number and title.
Inside the body of the loop, we can print those variables using an f-string.
If f-strings are new to you, there's a video on them linked in the description.
Inside the f-string, we'll print the number, a dot, and then the title.
If we run the code, our output is close to what we want.
But the numbers start from zero since that's the default behavior of the enumerate function.
To change this, we can pass the argument start equals one to the enumerate function.
Running the code again, our four songs come out cleanly numbered one through four.
Okay, that's a good start on the final output we're building towards.
Next, we'll add each song's duration.
Those lengths are given to us in a second list called durations, lined up with their titles list.
To loop through both lists together, we hand them to the zip function right inside the enumerate call.
And yes, you can nest these functions.
Enumerate happily works on any sequence we give it, and the result of zip is just a sequence of tuples.
Zip pairs list items by position. So now enumerate hands us a number and a pair on each pass.
That means we need to unpack that data in two layers.
First, the number produced by the enumerate function, then the title and duration from inside the tuple.
Once unpacked though, we can use all these just like any other regular variable in the loop body.
So to include the duration in the printed output, we simply add it to the F-string.
Running the code, every song now shows its length right next to its number.
Great, that's the main four songs done.
But the full tracklist we're building has three more bonus tracks.
These bonus tracks are waiting in their own two lists, bonus titles and bonus durations.
We want to print them at the end of the tracklist, numbered to continue the count five, six, and seven rather than starting over at one.
To do this, we can reuse the loop we just wrote.
Just point it at the bonus lists instead.
The only other change is where the enumerate numbering begins.
The enumerate function's start argument can be any number we like, not just one.
Since the main album ends at track four, we pass start equals five instead of start equals one.
Then to keep the two sections distinct, we print a heading above each main album before the first loop and bonus tracks before the second.
Running the code, the bonus tracks now slot in under their own heading, numbered five through seven.
Awesome. We now have our finished track list nicely formatted.
The enumerate function gave us the numbering.
The zip function paired our lists together.
And combining the two let us do both at once.
Working with the tuples generated by enumerate and zip was also a key part of this video.
If you want to learn more about tuples and how they differ from lists and sets, check out our video linked in the description.
We're working on lots more Python explainer videos like this one, so be sure to subscribe so that you don't miss out. If you have any questions or topics that you'd like to learn more about, let us know in the comments below. We'd love to hear from you. Thanks for watching.
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23