Sometimes, while working with Python lists, we can have a problem in which we intend to find the position of maximum element of list. This task is easy and discussed many times. But sometimes, we can have multiple maximum elements and hence multiple maximum positions. Let’s discuss a shorthand to achieve this task in this case.
Method : Using
max() + enumerate() + list comprehension
In this method, the combination of above functions is used to perform this particular task. This is performed in two steps. In 1st, we acquire the maximum element and then access the list using list comprehension and corresponding element using enumerate and extract every element position equal to maximum element processed in step 1.
The original list : [8, 4, 6, 8, 2, 8] The Positions of maximum element : [0, 3, 5]
- Python | Get first element with maximum value in list of tuples
- Python | Maximum element in tuple list
- Python | Maximum and minimum element's position in a list
- Python | Group elements on break positions in list
- Python | Subtract two list elements if element in first list is greater
- Python | Replace elements in second list with index of same element in first list
- Python | Indices list of matching element from other list
- Python | Insert Nth element to Kth element in other list
- Python | Slicing list from Kth element to last element
- Python | Find maximum length sub-list in a nested list
- Python | Move one list element to another list
- Python | Maximum absolute difference list of list
- Python | Maximum sum of elements of list in a list of lists
- Python | Three element sum in list
- Python | How to get the last element of list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.