Open this example in the interactive library
Source code
scores = {'Ada': 90, 'Ben': 60, 'Amy': 85}
print({name: score for name, score in scores.items() if score >= 80})Sample output
{'Ada': 90, 'Amy': 85}
Filter dictionary values. A self-contained example using the Python standard library.
Open this example in the interactive library
scores = {'Ada': 90, 'Ben': 60, 'Amy': 85}
print({name: score for name, score in scores.items() if score >= 80}){'Ada': 90, 'Amy': 85}