/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Filter a dict def from_keys(d, iterator): return dict((i, d[i]) for i in iterator) mydict = {'apple':'red', 'banana':'yellow', 'orange':'purple'} print from_keys(mydict, 'apple orange'.split()) # {'orange': 'purple', 'apple': 'red'}