'Is there a way to add an intersection to a set in python?
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
Solution 1:[1]
You can just use the .intersection() method:
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.intersection(y)
print(z)
Solution 2:[2]
Thank you @"user2357112 supports Monica", that was infact the Problem... if I interchange it with
frozenset({x,x+1})
it totally works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | marky004 |
| Solution 2 | Malte Paulmann |
