Skip to content

Tag: min

Problems regarding “key” in the min() function

scores = {1:20, 2:40, 3:0, 4:25} min_score = min(scores, key=scores.get) I don’t quite understand the parameters that can be passed into the key. Running the above code gives me 3 which is what I wanted. scores.get return me a dict object at certain memory address. Calling scores.get() raised me an Error. key = scores complained that dict object is not

What functions can be used as ‘key=func’ arguments in the min() and max() functions?

For example: How do I know whether it is possible or not possible to use a function as a ‘key=func’ argument? Answer As indicated in the documentation, min() (and max()) expect a one-argument ordering function like that used for list.sort(). So, what’s expected is a function that takes a single argument from the collection that min() or max() is

Max and Min value for each colum of one Dataframe

Give this dataframe ‘x’: How I could get a list of pairs with the min and max of each column? The result would be: Answer You could define a function and call apply passing the function name, this will create a df with min and max as the index names: If you insist on a list of lists we can