Square and Even with Lambda
Python
15 pts
Square and Even with Lambda
Using lambda (not def), create:
square— returns a number multiplied by itselfis_even— returnsTrueif a number is even, otherwiseFalse
Then use them with map() and filter() on numbers = [1, 2, 3, 4, 5, 6] to create squares and evens (both lists), and print them.
Expected output:
[1, 4, 9, 16, 25, 36] [2, 4, 6]
Checklist
- Create
squarewithlambdaso that it returns a number multiplied by itself. - Create
is_evenwithlambdaso that it returnsTruefor even numbers andFalseotherwise. - Keep
numbersunchanged and usemap()andfilter()to create the listssquaresandevens. - Print
squares, thenevens.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
