Skip to content
Advertisement

Tag: max

Remove NaN in a python list using max

In a recent interview I was given the following problem. We have a list l = [NaN, 5, -12, NaN, 9, 0] and we want to replaceNaN with -9 using the max function knowing that max(NaN, -9) = -9. What I have tried is : but the output is still the same list. Can’t figure out how to code this.

Why can’t I use max with Python to find maximum one-digit integer in array?

I had an interview recently and was asked to solve the following problem using Python: Write a function: such that, given an array A consisting of N integers, it returns the maximum among all one-digit integers. For example, given array A as follows: the function should return 1. Assume that: N is an integer within the range [1…1,000] Each element

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(). https://docs.python.org/3/library/functions.html#min So, what’s expected is a function that takes a single argument from the collection that min() or max() is

Advertisement