select present keys
Input
select_keys({'a': 1, 'b': 2, 'c': 3}, ['b', 'c'])
Output
{'b': 2, 'c': 3}
Only 'b' and 'c' are selected and included in that order.
Full lesson preview
Return a new dictionary containing only given keys from the source, inserting a default for missing keys.
Problem statement
Task
Examples
Input
select_keys({'a': 1, 'b': 2, 'c': 3}, ['b', 'c'])
Output
{'b': 2, 'c': 3}
Only 'b' and 'c' are selected and included in that order.
Input format
Output format
Constraints
Samples
Input
select_keys({'a': 1}, ['a', 'b'], default=None)
Output
{'a': 1, 'b': None}
Missing 'b' is included with default None.