Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Keep only dictionary entries above a value limit

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

Python practice14 minDictionaries & SetsIntermediateLast updated March 18, 2026

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}

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 1

Input

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

Output

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

x and y are above 4; z is not.