Python: Check if one dictionary is a subset of another larger dictionary

前端 未结 16 690
轮回少年
轮回少年 2020-12-04 09:29

I\'m trying to write a custom filter method that takes an arbitrary number of kwargs and returns a list containing the elements of a database-like list that contain

16条回答
  •  忘掉有多难
    2020-12-04 10:11

    If you don't mind using pydash there is is_match there which does exactly that:

    import pydash
    
    a = {1:2, 3:4, 5:{6:7}}
    b = {3:4.0, 5:{6:8}}
    c = {3:4.0, 5:{6:7}}
    
    pydash.predicates.is_match(a, b) # False
    pydash.predicates.is_match(a, c) # True
    

提交回复
热议问题