Explanation:
1. Creating the List
nums = [[1, 2], [3, 4], [5, 6]]
We make a list named nums
It has three small lists inside it:
[1, 2]
[3, 4]
[5, 6]
2. Making the Function
def even_sum(x):
return sum(x) % 2 == 0
We create a function named even_sum
It receives one list x
sum(x) adds the elements
% 2 == 0 checks if the total is even
True → keep it
False → remove it
3. Using filter()
res = list(filter(even_sum, nums))
filter() applies even_sum on each small list in nums
Only lists with even sum will stay
Result is converted to a list and stored in res
4. Checking Each List
[1,2] → 1+2 = 3 (odd)
[3,4] → 3+4 = 7 (odd)
[5,6] → 5+6 = 11 (odd)
➡ No list has an even sum
5. Printing the Result
print(res)
It prints res
6. Final Output
[]


0 Comments:
Post a Comment