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

前端 未结 16 684
轮回少年
轮回少年 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条回答
  •  旧时难觅i
    2020-12-04 10:12

    for keys and values check use: set(d1.items()).issubset(set(d2.items()))

    if you need to check only keys: set(d1).issubset(set(d2))

提交回复
热议问题