d=dict(a=1,b=2,c=3) k=d.keys() #dict_keys(['a', 'b', 'c']) del d[ 'a' ] print (k) #k will dynamically change dict_keys(['b', 'c' ]) #The key of the dictionary is unique, supports intersection and union operations, d.values() is not allowed print (k|{ 'x' : 4 }) #{'c', 'b', 'x '} print (k&{ 'x' : 4 }) #set() print (d.items()|{ 'x' : 4 }) #{'x', ('b', 2), ('c ', 3)} print (d.items()&{ 'x' :4}) #set() print(d.values()|{'x': 4}) #报错TypeError: unsupported operand type(s) for |: 'dict_values' and 'dict'
Python dictionary supports intersection and union operations
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326000672&siteId=291194637
Ranking