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

前端 未结 16 683
轮回少年
轮回少年 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:08

    Convert to item pairs and check for containment.

    all(item in superset.items() for item in subset.items())
    

    Optimization is left as an exercise for the reader.

提交回复
热议问题