- Ax[1]
- B['B']
- CTrue
- DFalse
The remove()
and discard()
method removes the specified item from a set.
Python set
doesn’t allow duplicate items.
If you try to execute the above code you will get a TypeError: unhashable type: 'list'
When you set set2= set11
, you are making them refer to the same dict object, so when you modify one of them, all references associated with that object reflect the current state of the object. So don’t use the assignment operator to copy the set instead use the copy()
method or set()
constructor.
Question was not answered
Example:
A = {30, 20, 10}
B = {50, 30, 40}
print(A.symmetric_difference(B))
Output:
{40, 10, 50, 20}
The difference_update()
method removes the items that exist in both sets. Here set1.difference_update(set2)
removed the unwanted items from the original set1.