easy +8 pts

Filter by Age

Return names of people above a given age from a list of dictionaries.

Implement a function `filter_by_age(people, min_age)` that accepts a list of dictionaries, each with keys `'name'` (str) and `'age'` (int), and an integer `min_age`. It should return a new list containing the `'name'` of every person whose `'age'` is **greater than or equal to** `min_age`. The order of names in the output must match the order of people in the input. If no one meets the age threshold, return an empty list. **Function signature:** ```python def filter_by_age(people: list[dict], min_age: int) -> list[str]: ``` **Assumptions:** - `people` is a list of dictionaries; each dictionary contains exactly the keys `'name'` (non-empty string) and `'age'` (integer). - `min_age` is an integer. - The input list must NOT be modified.

Constraints

0 <= len(people) <= 10^4 -10^3 <= age <= 10^3 -10^3 <= min_age <= 10^3

Example

>>> filter_by_age([{'name': 'Alice', 'age': 25}, {'name': 'Bob', 'age': 30}], 26)
['Bob']
>>> filter_by_age([], 18)
[]
8 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Iterate over the list and check each person's age.
Use a list comprehension or a for loop with an if condition.
Append only the 'name' field when age >= min_age.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.