Created
June 6, 2018 21:00
-
-
Save Marva82/c1d7900a32189d7e473f6064545b941f to your computer and use it in GitHub Desktop.
Getting all subsets from a list using Recursion 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
''' | |
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