2022-10-03 01:33:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
def filter_dict_by_set(dictionary: dict, valid_keys: set):
|
2022-10-04 00:50:59 +03:00
|
|
|
""" create new dict with key value pairs of dictionary, where key is in valid_keys """
|
2022-10-03 01:33:06 +03:00
|
|
|
new_dictionary = {}
|
|
|
|
|
|
|
|
for key, value in dictionary.items():
|
|
|
|
if key in valid_keys:
|
|
|
|
new_dictionary[key] = value
|
|
|
|
|
|
|
|
return new_dictionary
|
2022-10-04 00:50:59 +03:00
|
|
|
|
|
|
|
|
|
|
|
def pop_from_dict_by_set(dictionary: dict, valid_keys: set):
|
|
|
|
""" remove and create new dict with key value pairs of dictionary, where key is in valid_keys """
|
|
|
|
new_dictionary = {}
|
|
|
|
|
|
|
|
for key in list(dictionary.keys()):
|
|
|
|
if key in valid_keys:
|
|
|
|
new_dictionary[key] = dictionary.pop(key)
|
|
|
|
|
|
|
|
return new_dictionary
|