0

I have two methods max(x, y) and min(x, y) which return maximum and minimum values of the arguments passed to them respectively.

I need to make a call to each one of them using lambda function something like...

funWithNum = [lambda  x: funWithNum[0], max  ,  lambda y: funWithNum[1], min]
print funWithNum[0](1, 2)
print funWithNum[1](1, 2)

When I use print funWithNum[0](1, 2), I should get max number and when I use print funWithNum[1](1, 2), I should get min number. How do I achieve this?

5
  • 1
    Hint: How would you do it if you didn't have lambda? Commented Jul 4, 2015 at 7:49
  • 1
    Why not just put max and min in the list, nothing else? Commented Jul 4, 2015 at 7:49
  • classic XY problem. Describe what you want to do, not how Commented Jul 4, 2015 at 7:50
  • 3
    The first lambda function returns itself. The second one returns max. I recommend doing some more research on what lambda is. Commented Jul 4, 2015 at 7:50
  • You say that max & min are methods, but in your code they look more like ordinary functions. Are they functions that you've written, or are they Python's built-in max & min functions? Commented Jul 4, 2015 at 8:45

1 Answer 1

7

Why does everyone always think they need lambda functions!? You don't.

>>> fwn = [max, min]
>>> fwn[0](1,2)
2
>>> fwn[1](1, 2)
1
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.