Created
May 15, 2018 00:58
-
-
Save AhmedZahid098/0dcd0b84cb44e099fc76c6e6157960f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sets are unordered collections of unique and immutable objects, sets are useful for common tasks | |
# such as filtering out duplicates, isolating differences, and performing order-neutral | |
# equality tests without sorting in lists, strings, and all other iterable objects | |
# Creating sets --> set('elements') or {'elements'} | |
X = set("ahmed") | |
print(X) | |
Y = {'z', 'a', 'h', 'i', 'd'} | |
print(Y) | |
# Intersection --> set1 & set2 | |
print(X & Y) | |
# Union --> set1 | set2 | |
print(X | Y) | |
# Difference --> set1 - set2 | |
print (X - Y) | |
print (Y - X) | |
# Superset --> set1 > set2 | |
print(X > Y) | |
print(Y > X) | |
# Sets filter out the duplicate elements | |
print({1, 2, 3, 1, 2, 3}) | |
# Ordered neutral eqaulity test | |
print({'spam'} == {'aspm'}) | |
# Membership test | |
print('a' in X) | |
print ('z' in Y) | |
print('p' in set('spam')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment