map with list
Imagine a case where you apply several expensive (time consuming) transformations to some original list and then you iterate over the end-results looking for the first value that matches some condition. What if you find the value you were looking for after only a few iteration. Then making all that expensive calculations to the whole list was a waste of time.
This lazy evaluation can help you save both memory and time and you always have the option to force the immediate calculation by calling the list function.
def double(num): return 2 * num numbers = [1, 2, 3, 4] double_numbers = list(map(double, numbers)) print(double_numbers)
[2, 4, 6, 8]