Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Sets revisited in python
- def union(list1, list2):
- result = list(set(list1 + list2))
- print("Union of {} and {} is {}".format(list1, list2, result))
- def intersect(list1, list2):
- result = [x for x in list1 if x in list2]
- print("Intersection of {} and {} is {}".format(list1, list2, result))
- def difference(list1, list2):
- result = [x for x in list1 if x not in list2]
- print("Difference of {} and {} is {}".format(list1, list2, result))
- def cross_product(list1, list2):
- result = [(x * y) for x in list1 for y in list2]
- print("Cross product of {} and {} is {}".format(list1, list2, result))
- def equality(list1, list2):
- result = list1 == list2
- print("Equality of {} and {} is {}".format(list1, list2, result))
- def subset(list1, list2):
- result = set(list1) < set(list2)
- print("Subset of {} and {} is {}".format(list1, list2, result))
- def proper_subset(list1, list2):
- result = set(list1) < set(list2) and list1 != list2
- print("Proper subset of {} and {} is {}".format(list1, list2, result))
- def complement(list1, list2):
- result = [x for x in list2 if x not in list1]
- print("Complement of {} and {} is {}".format(list1, list2, result))
- complement([1,2,3,4], [1,4,2,6])
Add Comment
Please, Sign In to add comment