reduce() functions bring a bit of functional programming to Python. All three of these are convenience functions that can be replaced with List comprehensions or loops but provide a more elegant and short-hand approach to some problems
filter() takes a function object and an iterable and creates a new list. As the name suggests,
filter() forms a new list that contains only elements that satisfy a certain condition.
def starts_with_A(s): return s == "A" fruit = ["Apple", "Banana", "Pear", "Apricot", "Orange"] filter_object = filter(starts_with_A, fruit) print(list(filter_object))
It can be also done by using a lambda function like map().