filter dict by list of keys python 1

filter dict by list of keys python

dict_you_want = { your_key: old_dict[your_key] for your_key in your_keys }

Here is what the above code is Doing:
1. Create a new dictionary
2. For each key in your_keys, add the key and the value from old_dict to the new dictionary

Similar Posts