Explanation:
1. Create a dictionary of scores
scores = {"A": 85, "B": 72, "C": 90}
This stores names as keys and their scores as values.
2. Set the minimum score option
opt = {"min": 80}
This option decides the minimum score required to pass the filter.
3. Filter dictionary keys
res = list(filter(lambda k: scores[k] >= opt["min"], scores))
filter loops over the dictionary keys ("A", "B", "C").
scores[k] gets each key’s value.
Keeps only keys whose score is ≥ 80.
list() converts the result into a list.
4. Print the filtered result
print(res)
Displays the keys that passed the condition.
Output
['A', 'C']

0 Comments:
Post a Comment