0
def sum_(f, start, end):
    # 1st_value,_,__ = map(f,[start,end]) # how to get 1st value passed on lambda function here ? 
    # print(1st_value+start+end)
    return
if __name__ == '__main__':
    print(sum_(lambda y: 1.0, 5, 10))) # 1st_value=1.0,2nd_value=5, 3rd_value=10

How can i get 1.0 value from lambda function inside sum_()? I tried map(), but it did not work.

I have gone to other similar questions too, but did not find my answer, so please don't mark it duplicate.

0

1 Answer 1

2

You need to call the lambda function; you have passed the lambda function to the function sum_, but you are not calling the lambda :

>>> def sum_(f, start, end):
        value = f(None) # Pass value of y
        print(start-end+value)
>>>> sum_(lambda y: 1.0, 5, 10)
-4.0

A side note, 1st_value that you have in commented part of the code is not a valid variable name.

Sign up to request clarification or add additional context in comments.

4 Comments

When i try that It gives a type error: 'tuple' object is not callable
@Abhisheksoni, the solution now has the modified version of your code. It is working fine! Give it a try
thanks that above piece of code works but why this is not working then ? f = lambda y: 1.0, 5, 10 print(f(None) )
` f = lambda y: 1.0, 5, 10` creates a tuple, and the first item in the tuple contains lambda function, it will work if you call first item in this tuple by: f[0](None)

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.