# set实现

set() 函数创建一个无序不重复元素集，可进行关系测试，删除重复数据，还可以计算交集、差集、并集等。
set的issubset方法，a.issubset(b) :判断集合 a 的所有元素是否都包含在集合 b 中

a = {"a": 1}
b = {"a": 1, "b": 2}

aa = set(a.items())
print(aa)
bb = set(b.items())
print(bb)

print(aa.issubset(bb))


{('a', 1)}
{('a', 1), ('b', 2)}
True


# 自定义判断方法

a = {"a": [1, 2]}
b = {"a": [1, 2], "b": 2}

aa = set(a.items())


Traceback (most recent call last):
File "D:/demo/b.py", line 4, in <module>
aa = set(a.items())
TypeError: unhashable type: 'list'


a的值换成一个dict类型，也是会报错TypeError: unhashable type: 'dict'

a = {"a": {"c": 3}}
b = {"a": {"c": 3}, "b": 2}

aa = set(a.items())


# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/

def dict_a_in_b(dict_a, dict_b):
'''is dict_a in dict_b, return True/False'''
result = None
for key in dict_a:
if (key in dict_b) and (dict_a[key] == dict_b[key]):
result = True
else:
return False
return result

if __name__ == '__main__':
a = {"a": {"c": 3}}
b = {"a": {"c": 3}, "b": 2}
print(dict_a_in_b(a, b))


# 实际应用

{
'code': 0,
'msg': 'success!',
}


# 作者-上海悠悠 QQ交流群:717225969
# blog地址 https://www.cnblogs.com/yoyoketang/

def dict_a_in_b(dict_a, dict_b):
'''is dict_a in dict_b, return True/False'''
result = None
for key in dict_a:
if (key in dict_b) and (dict_a[key] == dict_b[key]):
result = True
else:
return False
return result

# 预期结果
expected = {'code': 0, 'msg': 'success!'}
# 实际结果
actual_result = {
'code': 0,
'msg': 'success!',