Lambda evaluation

  • Thread starter Joshua Ginsberg
  • Start date
J

Joshua Ginsberg

So this part makes total sense to me:
.... d[x] = lambda y: y*x
....
9

Because x in the lambda definition isn't evaluated until the lambda is
executed, at which point x is 3.

Is there a way to specifically hard code into that lambda definition the
contemporary value of an external variable? In other words, is there a
way to rewrite the line "d[x] = lambda y: y*x" so that it is always the
case that d[1](3) = 3?

Thanks!

-jag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top