I am trying to construct a function called maxSquare. In which it takes a list of integers X and returns Xi with the maximum square value, without using loops.

Sample Input/Output

>>> maxSquare([5, ‐7, 3])
-7


If you coul help me with this, I would appreciate it.

Thanks in advance.

Consider how could you do it with key argument There is one built in function, which puts numbers in same order as square, so even you do not need lambda or def.

Consider how could you do it with key argument There is one built in function, which puts numbers in same order as square, so even you do not need lambda or def.

This is what I have done

import operator 
   return (max(map(lambda x:operator.pow(x, 2), [5,-7,3])))

I am almost there, but how can I return the original value which is -7 ?

def max_square(x):
     return max(x, key=abs)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.