- []
List comprehension - simple expression
examples/functional/list_comprehension_simple.py
import sys numbers = [0, 1, 2, 3] sqrs = map(lambda n: n*n, numbers) print(sqrs) # <map object at 0x7fdcab2f5940> print(list(sqrs)) # [0, 1, 4, 9] print(sys.getsizeof(sqrs)) print() squares = [n*n for n in numbers] print(squares) # [0, 1, 4, 9] print(sys.getsizeof(squares))
<map object at 0x7fa9cf2eb9e8> [0, 1, 4, 9] 56 [0, 1, 4, 9] 96