Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 13

Keep only dictionary entries above a value limit

Medium

14 minute session

Summary

Filter a dictionary to retain only entries whose values are strictly greater than a given limit.

Problem statement

Given a dictionary mapping keys to numeric values and a numeric limit, return a new dictionary that contains only the entries whose values are strictly greater than the provided limit. Preserve the original insertion order of keys from the input dictionary for the resulting dictionary.

Task

Write a function that returns a new dictionary containing only the key-value pairs from the input dictionary whose values are greater than a provided numeric limit.

Examples

Filter values above 4

Input

filter_dict_by_value({'a': 5, 'b': 2, 'c': 8}, 4)

Output

{'a': 5, 'c': 8}

Explanation

Only 'a' (5) and 'c' (8) are greater than 4, so they are kept in the result in the same relative order as the input.

Input format

A dictionary d and a numeric limit value (int or float). Example: {'a': 1, 'b': 3}, 2

Output format

A dictionary containing only the key-value pairs from d where value > limit.

Constraints

- Values in the dictionary will be numeric (int or float). - Do not modify the original dictionary; return a new dictionary. - Preserve key insertion order from the original dictionary in the output.

Samples

Sample input 0

filter_dict_by_value({'x': 10, 'y': 5, 'z': 0}, 4)

Sample output 0

{'x': 10, 'y': 5}

Explanation 0

x and y are above 4; z is not.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

09:08 PM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.