Python Practice Lab
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:

LineTaskUse
1Squares of the odd numbersfilter() then map()
2Sum of the even numbersfilter() and sum()
3Numbers 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.

Hints

Saved
Custom 1

This is your own input, so Run will show what your program prints but can't say whether it's correct.