Python‎ > ‎set‎ > ‎

set.difference_update()

http://www.adilwaseem.com/

Definition
Remove all elements of another set from this set.

Syntax
set(x).difference_update(y)

Parameters
x,y=sets

Example
The return is:
 set1={3,45,344,66}
set2={1,44,66}
set3=set1.difference(set2)
set1.difference_update()
print("set1's new different items are: ", set1)

>>> 
set1's new different items are: {344, 66, 3, 45}
>>> 

set.difference_update()
The method updated the difference between set(a) and b.
 >>> from decimal import Decimal
>>> a=set()
>>> a.add(Decimal(1).adjusted())
>>> a.add(Decimal(.55).canonical())
>>> a.add(Decimal(-1).compare_signal(1))
>>> a
{0, Decimal('0.5500000000000000444089209850062616169452667236328125'), Decimal('-1')}
>>> b=set()
>>> b.add(Decimal(1).compare_total(2))
>>> b.add(Decimal(0.1).copy_abs())
>>> b
{Decimal('0.1000000000000000055511151231257827021181583404541015625'), Decimal('-1')}
>>> a.difference_update()
>>> a
{0, Decimal('0.5500000000000000444089209850062616169452667236328125'), Decimal('-1')}

Comments