Is there a way to add an intersection to a set in python?

523 Views Asked by At

For example:

A=set(frozenset[x,x+1]for x in range (10))
B=set()
C=set()
Result=set()
for B in A:
      for C in A:
            if B!=C:
                 Result.add(frozenset(B.intersection(C)))

#Error: descriptor 'intersection' for 'frozenset' objects doesn't apply to a 'types.GenericAlias' object

2

There are 2 best solutions below

1
marky004 On

You can just use the .intersection() method:

x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}

z = x.intersection(y)

print(z)
0
Malte Paulmann On

Thank you @"user2357112 supports Monica", that was infact the Problem... if I interchange it with

frozenset({x,x+1})

it totally works.