Saturday, November 21
Trending
- AI-Powered Cyberattacks in 2026: How Hackers Use AI Agents
- US Outages Explained: What Happened to Microsoft, FAA and Banks
- Microsoft 365 Outage: Outlook, Teams and Copilot Down. What We Know
- Diwali Online Shopping Scams 2026: 10 Ways to Stay Safe
- 10 Best DDoS Protection Services for 2027
- 12 Best Web Application Firewalls (WAF) for 2027
- Best Ethical Hacking Tools in 2027: Free & Paid Picks
- Software supply chain attacks 2026: Timeline and developer checklist
Overview
The map(), filter() and 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() function
Similar to map(), 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.
Syntax
filter(function, iterables(s))
Example
def starts_with_A(s): return s[0] == "A" fruit = ["Apple", "Banana", "Pear", "Apricot", "Orange"] filter_object = filter(starts_with_A, fruit) print(list(filter_object))
Output:
['Apple', 'Apricot']
It can be also done by using a lambda function like map().



