Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

replace None (for Python 2)

In Python 2 map used to extend the shorter lists by None values. So to avoid exceptions, we had some exra code replacing the None values by 0, using the ternary operator.

v1 = [1, 3, 5, 9]
v2 = [2, 6, 4, 8, 10]

print(map(lambda x,y: (0 if x is None else x) + (0 if y is None else y), v1, v2))
# [3, 9, 9, 17, 10]

Output: