噜噜哒
1234567891011121314def is_subdict(dict1, dict2): '''tell whether dict2 is a part of dict1 判断字典dict2是否为dict1的子集 >>> is_subdict({'a': 1, 'b': 2}, {'a': 1}) True >>> is_subdict({'a': 1, 'b': 2}, {'c': 3}) False ''' d = dict(dict1, **dict2) return d == dict1 if __name__ == '__main__': import doctest doctest.testmod()