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

前端 未结 16 682
轮回少年
轮回少年 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
    慢半拍i (楼主)
    2020-12-04 10:17

    Note for people that need this for unit testing: there's also an assertDictContainsSubset() method in Python's TestCase class.

    http://docs.python.org/2/library/unittest.html?highlight=assertdictcontainssubset#unittest.TestCase.assertDictContainsSubset

    It's however deprecated in 3.2, not sure why, maybe there's a replacement for it.

提交回复
热议问题