'enumerate' function There are different ways of accessing the data from a list like using range and then index or accessing the element of a list directly from for loop and so on. One other powerful way is by using 'enumerate' function. One major advantage of using 'enumerate' is this function returns both index and corresponding element at once. So, we don't have to maintain a counter to calculate the index or need to retrieve the element from a index. This makes the code easy to maintain and understand. In this post, we will see how to use 'enumerate' function and looping over a list to access index and elements as a tuple and also by using tuple unpacking . Syntax enumerate(iterable, start=0) 'enumerate' function accepts two parameters. 'iterable' - This is a mandatory parameter. An iterable (E.g.: list, tuple, string...) on which we need to run the loop and retrieve index and element. 'start' - This is an optional p...
Code with PR - Technical tips on coding and more...