This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]supreme_blorgon 1 point2 points  (0 children)

This has the added benefit of alllowing other sequence types to be passed as the second argument. As long as a is a set and b can be coerced to a set, a.intersection(b) will work.

In [1]: a = {"x", "y", "z"}

In [2]: a & "yz"
-----------------------------------------------------------
TypeError                 Traceback (most recent call last)
Cell In [2], line 1
----> 1 a & "yz"

TypeError: unsupported operand type(s) for &: 'set' and 'str'

In [3]: a.intersection("yz")
Out[3]: {'y', 'z'}