Ask Your Question

amadeo_'s profile - activity

2022-05-23 11:44:17 +0200 received badge  Popular Question (source)
2018-04-16 20:07:36 +0200 received badge  Nice Question (source)
2018-04-16 10:10:11 +0200 received badge  Student (source)
2018-04-16 08:32:37 +0200 asked a question Subset function

I am new to Sage and trying to define a recursive function that returns the subsets for a given set. I get some sort of memory error for even the smallest sets and I don't know why:

def MySubsets(L):
    if L == []:
        return [[]]

    TheSubsets = MySubsets(L[1:len(L)])

    for subset in TheSubsets:
        newSubset = copy(subset)
        newSubset.append(L[0])

        TheSubsets.append(newSubset)

    return TheSubsets

...and while MySubsets([]) works, MySubsets([1]) already yields a memory error.

2018-04-16 08:32:34 +0200 asked a question subset function

I am new to Sage and trying to define a recursive function that returns the subsets for a given set. I get some sort of memory error for even the smallest sets and I don't know why:

def MySubsets(L): if L == []: return [[]]

TheSubsets = MySubsets(L[1:len(L)])

for subset in TheSubsets:
    newSubset = copy(subset)
    newSubset.append(L[0])

    TheSubsets.append(newSubset)

return TheSubsets

...and while MySubsets([]) works, MySubsets([1]) already yields a memory error.