A comment I saw on Google+ was, "Is there an easy way to find out what number element of a list is maximum / minimum in Python?" The first line I came up with was the code on the first line, but is the second line better?

max(xrange(len(x)), key=lambda i: x[i])
max(enumerate(x), key=lambda x: x[1])[0]

Recommended Posts

A comment I saw on Google+ was, "Is there an easy way to find out what number element of a list is maximum / minimum in Python?" The first line I came up with was the code on the first line, but is the second line better?
python: Tips for displaying an array (list) with an index (how to find out what number an element of an array is)
How to identify the element with the smallest number of characters in a Python list?
An easy way to pad the number with zeros depending on the number of digits [Python]
[Completed version] Try to find out the number of residents in the town from the address list with Python
How to count the number of occurrences of each element in the list in Python with weight
How to find the first element that matches your criteria in a Python list
Find the maximum value, minimum value, and number of elements when the integer N is on the first line of the standard input and N integers follow.
How to run the practice code of the book "Creating a profitable AI with Python" on Google Colaboratory
[CleanArchitecture with Python] Apply CleanArchitecture step by step to a simple API and try to understand "what kind of change is strong" in the code base.
What is the fastest way to create a reverse dictionary in python?
[Python] Precautions when finding the maximum and minimum values in a numpy array with a small number of elements
In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
I'm an amateur on the 14th day of python, but I want to try machine learning with scikit-learn
If branch depending on whether there is a specific element in the list
How to get a list of files in the same directory with python
I want to make the LED Lighting of ErgoDox EZ shine, but tell me what the LED is in the first place