+ 1
How does lambda work
4 Respuestas
+ 7
Lambda is covered in the tutorial. Can you be a little more specific about which part is troubling you? cause the tutorial gave quite some examples to play with, to help understanding.
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2460/
Please tag relevant words, e.g. Python lambda, rather than 'not sure' ...
+ 1
Have a look at this snippet, herein we use lambda to square each number in a list, and filter odd and even numbers. Tell me how much of it you got, and what you haven't ...
numbers = [ 1, 2, 3, 4, 5, 6 ]
squared_numbers= list( map( lambda n: n ** 2, numbers ) )
odd_numbers = list( filter( lambda n: n % 2, numbers ) )
even_numbers = list( filter( lambda n: not n % 2, numbers ) )
print( 'List of numbers', numbers )
print( 'Square each number', squared_numbers )
print( 'Filter the odd numbers', odd_numbers )
print( 'Filter the even numbers', even_numbers )
Idk how far you've got through with the tutorial, but maps & filter chapter came right after the chapter about lambdas
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2461/
+ 1
Samain Salia
The thread still have 'not sure' in the tags. Kindly edit it to be more relevant, it's up there ☝
0
mostly the maps and filters part