Explanation:
Create a list
nums = [1, 2, 3]
A list named nums is created with three elements: 1, 2, and 3.
Apply map()
result = map(lambda x: x * 2, nums)
map() creates an iterator that will apply lambda x: x * 2 to each element of nums.
Important: At this point, no calculation happens yet — map() is lazy.
Clear the original list
nums.clear()
This removes all elements from nums.
Now nums becomes an empty list: [].
Convert map to list and print
print(list(result))
Now iteration happens.
But nums is already empty.
So map() has no elements to process.
Final Output
[]
.png)

0 Comments:
Post a Comment