-
Notifications
You must be signed in to change notification settings - Fork 39
Sets
ZekeLabs Technologies Private Limited edited this page Dec 12, 2016
·
1 revision
##Introduction
- Set is an iterable data-structure.
- It will contain only unique elements.
- Order of insertion is not maintained.
- Mutable DS
###Creation s = set() s = set([1,2,3,3,1])
###Union s1 = set([1, 2, 3]) s2 = set([1, 2, 3, 4, 6, 7])
s1 | s2 => Returns a new set, doesn't modify any of s1 or s2. s1.union(s2) => Returns a new set containing both.
###Intersection s1 & s2 => Returns a new set containing intersection of both the sets s1.intersection(s2)
###difference s1 - s2 => returns elements that is present in s1 & not in s2 s1.difference(s2)
###symmetric_difference s1 ^ s2 => Returns symmetric difference s1.symmetric_difference(s2)
###isdisjoint s1.isdisjoint(s2) => Returns true is none of the elements are in common
###Three types of updates are present in sets -
- difference_update
- intersection_update
- symmetric_difference_update