def powerset(x):
total1 = [[]]
total2 = [[]]
for a in x:
for b in total1:
c = list(b + [x[a]])
total2.append(c)
total1 = total2
# the total 1 and total 2 system should prevent it
# from creating an infinite loop when we add to the total.
print (total1)
f = [1,2,3]
g = powerset(f)
print (g)
Hier ist mein Versuch, ein Powerset für ein Intro Data Science-Klasse zu erstellen. Wenn ich das ausführe, erhalte ich als Ausgaben, bevor der Speicher ausgeht. Ich verstehe nicht, warum es [[], [2]]
zurückgibt, noch warum es nicht genügend Speicher hat, da Summe 1 außerhalb der Schleife geändert wird.Powerset-Funktion nicht genügend Arbeitsspeicher
g sollte einen Leistungssatz von f zurückgeben.
könnte jemand erklären, was ich falsch mache?
'für eine in x 'iss * nicht * iteriert über * Indizes *, sondern über die Elemente in' x'. –