Created
June 13, 2015 03:39
-
-
Save damzam/ca64b897a4cb9f818003 to your computer and use it in GitHub Desktop.
Create a superset efficiently in Python
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
#!/usr/bin/env python | |
""" | |
Create a superset from the integers provided | |
e.g. ./superset.py 1 2 3 | |
[set([]), set([1]), set([2]), set([3]), set([1, 2]), | |
set([1, 3]), set([2, 3]), set([1, 2, 3])] | |
""" | |
import sys | |
def main(*numbers): | |
sets = [set([])] | |
for n in numbers: | |
sets.extend([s | {n} for s in sets]) | |
print sets | |
if __name__ == '__main__': | |
numbers = [int(i) for i in sys.argv[1:]] | |
main(*numbers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment