Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Lambda function
#4
Just a gentle reminder - quote from PEP 8 -- Style Guide for Python Code >>> Programming Recommendations

Quote:Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier.

Yes:

def f(x): return 2*x

No:

f = lambda x: 2*x

The first form means that the name of the resulting function object is specifically 'f' instead of the generic '<lambda>'. This is more useful for tracebacks and string representations in general. The use of the assignment statement eliminates the sole benefit a lambda expression can offer over an explicit def statement (i.e. that it can be embedded inside a larger expression)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Messages In This Thread
Lambda function - by Uchikago - Jul-16-2019, 02:24 AM
RE: Lambda function - by Gribouillis - Jul-16-2019, 04:54 AM
RE: Lambda function - by millpond - Jul-16-2019, 05:17 AM
RE: Lambda function - by perfringo - Jul-16-2019, 08:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Add two resultant fields from python lambda function klllmmm 4 848 Jun-06-2023, 05:11 PM
Last Post: rajeshgk
  Writing a lambda function that sorts dictionary GJG 1 1,985 Mar-09-2021, 06:44 PM
Last Post: buran
  translating lambda in function fabs 1 2,121 Apr-28-2020, 05:18 AM
Last Post: deanhystad
  Lambda function recursion error DeadlySocks 1 2,008 Apr-13-2020, 05:09 PM
Last Post: deanhystad
  Lambda function error localsystemuser 3 4,659 Jan-29-2020, 01:43 PM
Last Post: DeaD_EyE
  Help with AWS Lambda function faws2019 0 1,556 Aug-27-2019, 01:54 PM
Last Post: faws2019
  eval lambda function with restricted context Olivier 7 5,067 Mar-04-2019, 10:45 PM
Last Post: Olivier
  Using a lambda function within another function JChapman 8 5,336 Jan-08-2019, 01:54 PM
Last Post: JChapman
  Write lambda function in pyhhon to coy data from multiple JSON into a single JSON fil anandmn85 2 4,185 Apr-19-2018, 05:56 AM
Last Post: anandmn85
  How do I make an assignment inside lambda function? Standard_user 2 19,905 Nov-13-2016, 05:54 PM
Last Post: Standard_user

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020