+ 2
How to use enumerate?
I remember I learnt this but I forgot what it means and forgot where I learnt it. Can someone please explain what it does and give an example? Or just tell me what section to find it in. All help appreciated.
4 Answers
+ 3
So bascially enumerate() creates an enumeration object, but to get around it, you can use tuple, list, etc.
Its function: For every element in the list, it replaces it with a tuple containing the element's index followed by the element. For example,
a=[1,2,3,5]
print(list(enumerate(a))-->[(0,1),(1,2),(2,3),(3,5)]
+ 1
Thanks!
0
I've gotta thank you too! After a long time I got my answer marked as best answer!
0
😏