easyUnit 8 · Functions, Callbacks & lambda
P23. map, filter and lambda
Functions, Callbacks & lambda
Read a list of integers and use built-in functions with lambda:
| Line | Task | Use |
|---|---|---|
| 1 | Squares of the odd numbers | filter() then map() |
| 2 | Sum of the even numbers | filter() and sum() |
| 3 | Numbers sorted by absolute value (ties keep input order) | sorted() with key=lambda |
Input Format
- Line 1: integers separated by spaces
Output Format
- Line 1:
Odd squares: <list> - Line 2:
Sum of evens: <n> - Line 3:
Sorted by absolute value: <list>
Constraints
- 1 ≤ number of integers ≤ 100
- -1000 ≤ each integer ≤ 1000
Sample Test Cases
Sample 1
Input
3 -4 5 2 -1
Output
Odd squares: [9, 25, 1] Sum of evens: -2 Sorted by absolute value: [-1, 2, 3, -4, 5]
Sample 2
Input
2 4 6
Output
Odd squares: [] Sum of evens: 12 Sorted by absolute value: [2, 4, 6]
Submitting checks 2 sample cases and 3 hidden test cases.