Explanation:
1. range(8)
range(8)
generates numbers from 0 to 7:
0, 1, 2, 3, 4, 5, 6, 7
2. Applying filter()
filter(lambda n: n % 2, range(8))
The lambda checks:
n % 2
For each number:
0 % 2 = 0 → False
1 % 2 = 1 → True
2 % 2 = 0 → False
3 % 2 = 1 → True
4 % 2 = 0 → False
5 % 2 = 1 → True
6 % 2 = 0 → False
7 % 2 = 1 → True
So filter() keeps only the odd numbers:
1, 3, 5, 7
3. Applying map()
map(lambda n: n // 2, ...)
Now each filtered number is passed to:
n // 2
Calculation:
1 // 2 = 0
3 // 2 = 1
5 // 2 = 2
7 // 2 = 3
So map() produces:
0, 1, 2, 3
4. sum(x)
sum(x)
adds all the mapped values:
0 + 1 + 2 + 3
= 6
5. Final Output
6
