Operations with a limited set of operations in python dictionary keywords

The following is a snippet of code:

d = {1:1} keys = d.keys() print(keys & {1,2,3})# {1} d[2] = 2 print(keys & {1,2,3}) # {1,2} # keys() is a view/reference print({1,2}.issubset({1,2,3})) # True print(keys.issubset({1,2,3})) # 'dict_keys' object has no attribute 'issubset' 

This is stated in official documents of dictionary view objects :

Key representations are specified because their entries are unique and hashed ... Then these specified operations are available ("different" refers to either a different view or set): [&, |, ^, ^]

If the keys are given, why the specified operation on them is limited to these four infix operations. Why, for example, is an operation without side effects not allowed, such as issuperset or issubset ?

+5
source share
1 answer

Why, for example, does an operation fail without side effects, such as issuperset or issubset operation is not allowed?

They; you just need to use the >= and <= operators:

 print(keys <= {1, 2, 3}) 

They also support isdisjoint in the form of a method, since there is no operator for it:

 print(keys.isdisjoint({1, 2, 3})) 
+6
source

All Articles