Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways

Enumerate() in Python | Python for Data Science | Day 12

Hello, Python tribe! We hope you are enjoying our content so far. 
Today, we will be discussing a very easy topic – enumerate() in Python. So, without further ado, let’s quickly discuss what the enumerate() function does. Basically, enumerate() in Python is used to register the number of iterations, by returning a unique enumerate-type object.

Enumerate() in Python

Let’s code some examples to see how enumerate() functions.

Here, we have a list of IPL teams.

Enumerate() in Python

We create an enumerate() object called iplobj. You can also verify if an enumerate-type object is created using type(). Next, we convert the enumerate object i.e. iplobject into a list for printing it. The output is a s displayed above.

It implies that 0 corresponds to MI, 1 corresponds to RCb and so on. Thus, it enlists or enumerates the no. of iterations and displays them as a list of tuples

Consider the code below:

Carefully notice that we have specified another parameter in enumerate(). Here, 1 denotes the starting point of iteration. The default value is 0, But, we have implicitly specified 1 here. So, the displayed list starts from 1 here. 

Let’s try using enumerate() with a string.

Like the previous example, we have repeated the same steps but with a string. 

You may also read about enumerate() here:

https://www.w3schools.com/python/ref_func_enumerate.asp

Now that you know about enumerate(), attempt the questions below without seeking help from the solutions we have provided. 

Happy coding 🙂

We have covered 40+ complete Data Science company interviews from the candidates who cracked these interviews.
Data Science Companies interview questions
We also have 30+ e-books on Amazon, Insta Mojo and books which can be delivered directly on your email address
Complete Set of e-books from The Data Monk
Understand some of the very complex topics in Analytics which are asked in most of the interviews
The Data Monk Top Articles
How to become a Data Scientist? Complete study material, free resources and websites to practice
Become a Data Scientist 
Make your profile on our website and practice at least 5-7 questions per day. Be a part of ~2000 Analytics expert

Article By,
Yashika Khurana
Intern | The Data Monk

About TheDataMonkGrand Master

I am the Co-Founder of The Data Monk. I have a total of 6+ years of analytics experience 3+ years at Mu Sigma 2 years at OYO 1 year and counting at The Data Monk I am an active trader and a logically sarcastic idiot :)

Follow Me

Leave a reply