Python Lambda

Python Lambda

Creator
Created
Created
2019 Nov 5 3:14
Editor
Edited
Edited
2023 Oct 30 13:36
Refs
Refs

function do not need define with no need of name

simple function with remove def, bracket and one line
# lambda input : output name = lambda parameters: function(parameters) name(argument)
 

usually used for functions (for collections)

key variable need function variable (lambda type is 'function')
  • sort
collection.sort(key = len) collection.sort(key = lambda c:len(c))
  • filter
# return new list of items which return function to true by item parameter filter(function, list)
  • reduce
 
 
 
 
 
 
 

 

Recommendations