Created
July 30, 2018 19:33
-
-
Save JoaoCarabetta/068a9662fc107a0b36189a1918ca6cab 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
def suffix(alist): | |
if not len(alist): | |
return [[]] | |
else: | |
return [alist] + suffix(alist[1:]) | |
def preffix(alist): | |
if not len(alist): | |
return [[]] | |
else: | |
return [[]] + list(map(lambda x: [alist[0]] + x, preffix(alist[1:]))) | |
def power_set(alist): | |
def power_set_inner(alist, res): | |
if not len(alist): | |
return res | |
else: | |
return power_set_inner(alist[1:], res + list(map(lambda x: [alist[0]] + x, res))) | |
return power_set_inner(alist, [[]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment