Answers for "select from dict based on another dict python"

3

only keep few key value from dict

>>> dict_filter = lambda x, y: dict([ (i,x[i]) for i in x if i in set(y) ])
>>> large_dict = {"a":1,"b":2,"c":3,"d":4}
>>> new_dict_keys = ("c","d")
>>> small_dict=dict_filter(large_dict, new_dict_keys)
>>> print(small_dict)
{'c': 3, 'd': 4}
>>>
Posted by: Guest on September-18-2020
1

filter dict

{k: v for k, v in points.items() if v[0] < 5 and v[1] < 5}
Posted by: Guest on June-12-2020

Code answers related to "select from dict based on another dict python"

Python Answers by Framework

Browse Popular Code Answers by Language