Set

Set are like Dictionary but without key value pair, there are just element, if you convert a list to a a set it will remove all duplicate.

ipv4 = [‘10.10.10.1’, ‘10.10.10.1’, ‘10.10.10.4, ‘10.10.10.3, ‘10.10.10.3, ‘10.10.10.2, ‘10.10.10.2]
set(ipv4)
{‘10.10.10.1’, ‘10.10.10.4, ‘10.10.10.3 ‘10.10.10.2’}

To view the unique element of multiple set you can use the pipe command 
set1 | set2 <— this will return each unique element of the set.
set1.union(set2)

To view the duplicate element of multiple set, you can use the and command
set1 & set2 <— this will return each duplicate element of the set.
set1.extersection(set2)

To substract the element of multiple set, you can use the and command
set1 – set2
set1.intersection(set2)

 

 

 

Leave a Comment