How to filter a dict to contain only keys in a given list?

Viewed 22459

Both very new to Python and stackoverflow. Thank you for your patience, and your help.

I would like to filter a dict according to the content of a list like this:

d={'d1':1, 'd2':2, 'd3':3}

f = ['d1', 'd3']

r = {items of d where the key is in f}

Is this absurd? If not, what would be the right syntax?

Thank you for your help.

Vincent

2 Answers
Related