Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JoaoCarabetta/068a9662fc107a0b36189a1918ca6cab to your computer and use it in GitHub Desktop.
Save JoaoCarabetta/068a9662fc107a0b36189a1918ca6cab to your computer and use it in GitHub Desktop.
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