jmquintana79
7/25/2017 - 12:36 AM

optimal loops list

More optimal loops to iterate with list.


## MAP
items = [1, 2, 3, 4, 5]
def fx2(x):
  return x**2
squared = list(map(lambda x: fx2, items))


## FILTER
number_list = range(-5, 5)
less_than_zero = list(filter(lambda x: x < 0, number_list))

## REDUCE
from functools import reduce
items = [1, 2, 3, 4]
product = reduce((lambda x, y: x * y), items)