filter - map example
examples/functional/filter_map.py
numbers = [1, 7, 19, 5, 57, 23, 8] def big(x): print(f"filtering {x}") return x > 10 def double(y): print(f"double {y}") return 2*y big_numbers = filter(big, numbers) print(big_numbers) doubles = map(double, big_numbers) print(doubles) for num in doubles: print(num)
<filter object at 0x7ffad9f82f28> <map object at 0x7ffad9f829e8> filtering 1 filtering 7 filtering 19 double 19 38 filtering 5 filtering 57 double 57 114 filtering 23 double 23 46 filtering 8