Reviewed by Aditya Kumar · Last reviewed 2026-08-08
A higher order function either accepts one or more functions as arguments or returns a function as its result. In this context, filter above is a higher order function because it generates and returns…
This easy-level Python/Coding question appears frequently in data engineering interviews at companies like Chryselys. While less common, it tests deeper understanding that distinguishes strong candidates.
Start by clearly defining the core concept being asked about. Interviewers want to see that you understand the fundamentals before diving into implementation details. Structure your answer with a definition, then explain the practical application with a concise example. The expert answer includes a code example that demonstrates the implementation pattern.
A higher-order function either accepts one or more functions as arguments or returns a function as its result. In this context, filter_above is a higher-order function because it generates and returns a new filtering function (a lambda expression) tailored to a specific threshold.
filter_above function takes a threshold and returns a lambda function lambda x: x > threshold. This returned lambda is a predicate that can then be passed to Python's built-in filter() function, which is itself a higher-order function. filter() iterates through a sequence, applying the predicate to each element and yielding only those for which the predicate returns True. This pattern promotes reusability and composability, allowing you to easily create various filtering predicates without rewriting the core logic. For instance, you could pipe multiple such filters together. functools.partial offers an alternative way to create specialized versions of functions by "pre-filling" some of their arguments, effectively achieving a similar goal of creating a new function from an existing one.
DataFrame.filter() or RDD.filter() accept a function or an expression to define the filtering logic. Similarly, in Pandas, you often pass lambda functions or boolean conditions to filter DataFrames.
from functools import partial
def filter_above(threshold):
"""Returns a predicate function that checks if a value is greater than the threshold."""
return lambda x: x > threshold
numbers = [5, 12, 3, 18, 9, 22]
# Using filter_above to create a predicate
is_above_10 = filter_above(10)
filtered_numbers_1 = list(filter(is_above_10, numbers))
# Result: [12, 18, 22]
# Direct usage
filtered_numbers_2 = list(filter(filter_above(15), numbers))
# Result: [18, 22]
# Using functools.partial to create a specialized filter operation
# This creates a function that, when called with a list, filters it.
filter_gt10_operation = partial(filter, lambda x: x > 10)
filtered_numbers_3 = list(filter_gt10_operation(numbers))
# Result: [12, 18, 22]
Red Flag: Hardcoding threshold. Pro-Move: 'We use partial(filter, predicate) for configurable pipeline stages—threshold from config.'
Some links below are affiliate links. If you buy through them we may earn a small commission at no extra cost to you — it helps keep DataEngPrep free.
According to DataEngPrep.tech, this is one of the most frequently asked Python/Coding interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.