Created
May 10, 2020 14:42
-
-
Save elowy01/8c990c054cdae1a9f56d0a157c34f8b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
""" NOTES: | |
- requires Python 2.4 or greater | |
- elements of the lists must be hashable | |
- order of the original lists is not preserved | |
""" | |
def unique(a): | |
""" return the list with duplicate elements removed """ | |
return list(set(a)) | |
def intersect(a, b): | |
""" return the intersection of two lists """ | |
return list(set(a) & set(b)) | |
def union(a, b): | |
""" return the union of two lists """ | |
return list(set(a) | set(b)) | |
if __name__ == "__main__": | |
a = [0,1,2,0,1,2,3,4,5,6,7,8,9] | |
b = [5,6,7,8,9,10,11,12,13,14] | |
print unique(a) | |
print intersect(a, b) | |
print union(a, b) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment