You're getting a syntax error because an if expression has to include else, there's no default value.

But you don't need if here. The callback function of filter() just needs to return a boolean, so just use the comparison.

filtered_lst = filter(lambda x: x.startswith('A'), fruit_lst)

Note that filter() is generally not considered pythonic, conditional list comprehensions are usually preferred.

filtered_lst = [x for x in fruit_lst if x.startswith('A')]
Answer from Barmar on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › filter-in-python
filter() in python - GeeksforGeeks
DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 18 Mar, 2026 · filter() function is used to extract elements from an iterable (like a list, tuple or set) that satisfy a given condition.
Published: March 18, 2026
🌐
W3Schools
w3schools.com › python › ref_func_filter.asp
Python filter() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Training · ❮ Built-in Functions · Filter the array, and return a new array with only the values equal to or above 18: ages = [5, 12, 17, 18, 24, 32] def myFunc(x): if x < 18: return False else: return True adults = filter(myFunc, ages) for x in adults: print(x) Try it Yourself » ·
🌐
Python
docs.python.org › 3 › builtins › functions.html
Built-in Functions — Python 3.14.7 documentation
Note that filter(function, iterable) is equivalent to the generator expression (item for item in iterable if function(item)) if function is not None and (item for item in iterable if item) if function is None.
🌐
YouTube
youtube.com › watch
Learn Python FILTER() in 3 minutes! 🧹 - YouTube
#pythonprogramming #pythontutorial #python # filter(condition, collection) = return all elements that pass a condition
Published: July 20, 2024
🌐
Real Python
realpython.com › ref › builtin-functions › filter
filter() | Python’s Built-in Functions – Real Python
The built-in filter() function in Python is used to process an iterable and extract items that satisfy a given condition, as determined by a filtering function.
🌐
Mimo
mimo.org › glossary › python › filter
Python filter(): Syntax, Usage, and Examples
Use filter() to extract matching items from any iterable in Python. Write a condition, apply it, and return only the values that pass.
Find elsewhere
🌐
YouTube
youtube.com › watch
How to Use filter() in Python | Filter Data Like a Pro Using Python - YouTube
🔎 Learn How to Use the filter() Function in Python | Write Clean & Powerful Data Filters ()Want to filter out unwanted values from a list in a single, elega...
Published: June 9, 2025
🌐
DataCamp
datacamp.com › tutorial › python-filter
Python filter(): Keep What You Need | DataCamp
June 27, 2025 - Learn how Python filter() helps you extract elements that match a condition. Use it with custom functions, lambdas, or None for data filtering tasks.
🌐
IONOS
ionos.com › digital guide › websites › web development › python filter function
What is Python’s filter function and how to use it
May 26, 2025 - Python’s filter() function uses Boolean values to filter iterables. Find out how it works using our helpful examples.
🌐
CodeSignal
codesignal.com › learn › courses › projection-filtering-and-aggregation-of-data-streams › lessons › implementing-data-filtering-in-python
Implementing Data Filtering in Python
Previous LessonNext Lesson: Data Projection Techniques in Python ... class DataFilter: def filter_with_filter_function(self, data_stream): return list(filter(lambda item: item < 10, data_stream))
🌐
Medium
medium.com › @HeCanThink › exploring-filter-in-python-for-data-manipulation-c0ef11160f4b
Exploring filter() in Python for Data Manipulation 🤓 | by Manoj Das | Medium
July 20, 2023 - The filter() function in Python is a built-in higher-order function that filters elements from an iterable based on a given function’s result. It was designed to work with functions that return a Boolean value (True or False) for each element in the iterable.
🌐
Medium
medium.com › @walczak.coding › filtering-made-simple-how-pythons-filter-cleans-up-your-data-5e5177523a30
Filtering Made Simple: How Python’s filter() Cleans Up Your Data | by Jan Walczak | Medium
September 24, 2025 - filter() is a Python built-in that works like a sieve. The coolest part? Unlike a list comprehension, filter() doesn’t process everything at once. It’s lazy (in the best possible way). Instead of building a whole list in memory, it hands you items one by one, only when you actually ask for them.
🌐
Medium
medium.com › @datasciencejourney100_83560 › filter-function-in-python-0f7056ffc3a8
Filter Function in Python. The filter() function is used to filter… | by Rina Mondal | Medium
September 3, 2025 - The filter() function is used to filter elements from an iterable (such as a list, tuple, or dictionary) based on a specified condition. It…
🌐
YouTube
youtube.com › watch
Python Filter Function - Intermediate Python Tutorial - YouTube
Learn how to use the powerful Python filter() Function to filter lists, tuples, dictionaries, and more! Want a written a tutorial instead? Check out the tuto...
Published: May 23, 2022
🌐
DEV Community
dev.to › dailydevtips1 › python-filter-function-17f4
Python filter() function - DEV Community
June 4, 2021 - In general, filters are used to filter a sequence set, for instance, a list.
🌐
Programiz
programiz.com › python-programming › methods › built-in › filter
Python filter()
Online Python Online JavaScript ... Online Rust Online Scala Online Dart Online R Online Ruby ... The filter() function selects elements from an iterable based on the result of a function....
🌐
Python Academy
python-academy.org › functions › filter
filter — Python Function Reference
A comprehensive guide to Python functions, with examples. Find out how the filter function works in Python. Construct an iterator from those elements of iterable for which function returns true.