Skip to content

Instantly share code, notes, and snippets.

@Marva82
Created June 6, 2018 21:00
Show Gist options
  • Save Marva82/c1d7900a32189d7e473f6064545b941f to your computer and use it in GitHub Desktop.
Save Marva82/c1d7900a32189d7e473f6064545b941f to your computer and use it in GitHub Desktop.
Getting all subsets from a list using Recursion in Python
'''
Second part to recursion videos
Printing out all subsets of a list of numbers
using recursion
'''
def subset(input):
if input == []:
return [[]]
else:
a = subset(input[1:])
return a + [[input[0]] + b for b in a]
fullList = [4,6,12,1]
theSubSets = subset(fullList)
print(theSubSets)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment