Explanation:
1. Initialization:
nums = [1, 2, 2, 3]
We create a list nums containing 4 numbers: [1, 2, 2, 3]
These numbers will be the input for the next mapping step
2. Mapping / Transformation:
map(lambda x: x%2, nums)
lambda x: x%2 is a small function that returns the remainder when a number is divided by 2
Applied to each element:
1 % 2 → 1
2 % 2 → 0
2 % 2 → 0
3 % 2 → 1
Result after map → [1, 0, 0, 1]
3. Removing Duplicates using set():
set([1, 0, 0, 1])
set() removes all duplicate values and keeps only unique elements
[1, 0, 0, 1] → {0, 1}
4. Printing the Result:
print(res)
res now contains the set {0, 1}
Console output →
{0, 1}
Key Concepts:
map() → Applies a function to each element in a sequence
lambda function → A small anonymous function used directly with map
set() → Removes duplicates and keeps only unique values


0 Comments:
Post a Comment