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 🙂

The Data Monk Interview Books – Don’t Miss

Now we are also available on our website where you can directly download the PDF of the topic you are interested in. At Amazon, each book costs ~299, on our website we have put it at a 60-80% discount. There are ~4000 solved interview questions prepared for you.

10 e-book bundle with 1400 interview questions spread across SQL, Python, Statistics, Case Studies, and Machine Learning Algorithms – Ideal for 0-3 years experienced candidates

23 E-book with ~2000 interview questions spread across AWS, SQL, Python, 10+ ML algorithms, MS Excel, and Case Studies – Complete Package for someone between 0 to 8 years of experience (The above 10 e-book bundle has a completely different set of e-books)

12 E-books for 12 Machine Learning algorithms with 1000+ interview questions – For those candidates who want to include any Machine Learning Algorithm in their resume and to learn/revise the important concepts. These 12 e-books are a part of the 23 e-book package

Individual 50+ e-books on separate topics

Important Resources to crack interviews (Mostly Free)

There are a few things which might be very useful for your preparation

The Data Monk Youtube channel – Here you will get only those videos that are asked in interviews for Data Analysts, Data Scientists, Machine Learning Engineers, Business Intelligence Engineers, Analytics managers, etc.
Go through the watchlist which makes you uncomfortable:-

All the list of 200 videos
Complete Python Playlist for Data Science
Company-wise Data Science Interview Questions – Must Watch
All important Machine Learning Algorithm with code in Python
Complete Python Numpy Playlist
Complete Python Pandas Playlist
SQL Complete Playlist
Case Study and Guesstimates Complete Playlist
Complete Playlist of Statistics

Author: TheDataMonk

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 :)