+ 1

What is enumerate??

30th Aug 2020, 2:52 PM
Sadat Rahman
Sadat Rahman - avatar
2 Answers
+ 3
enumerate usually means to pack an iterables items together with their index number. https://code.sololearn.com/cz9NnT6uLcp8/?ref=app
30th Aug 2020, 3:05 PM
Slick
Slick - avatar
+ 2
It will iterate through a list and it will make a tuple of each item with an index starting at zero by default for example lst = ['first', 'second', 'third'] print(list(enumerate(lst))) The output will be list of tuples like this [(0, 'first'), (1, 'second'), (2,'third')] If you want to start insexing by one you can do it by a second argument like this lst = ['first', 'second', 'third'] print(list(enumerate(lst, 1))) This will give [(1, 'first'), (2, 'second'), (3,'third')]
30th Aug 2020, 3:05 PM
Ruba Kh
Ruba Kh - avatar