Alright python noob here, too lazy to post it on stack overflow.
I was writing a code to generate all subsets of a given set and why the fuck doesn't this code work:def GenSubset(set,length,start=0,prev=[]):
while start <= len(set) - length:
next = prev + [set[start]]
if length == 1:
yield next
else:
GenSubset(set,length-1,start+1,next)
start += 1
RandomSet = [0,1,2,3,4,5]
for list in GenSubset(RandomSet,3):
print(list)
if I change yield to print it works perfectly so I thought you just cant yield lists but I tested it and its not the case. And if I tell it to generate 1-length subsets it works perfectly
>>59134046
ayyyy good job with that np complete problem solution u got there bud
>>59134056
Yeah but the generator doesn't work...
>>59134119
if you run the code it doesn't crash, it doesn't output anything. changing yield to print shows it generates them properly but it cant output them. And when you write expample list generator it works perfectly. So once again What The Fuck
Welp no help I guess, gotta go to stack overflow anyway
>>59134354
Are you sure the non-generator portion of you code is correct?
>>59134598
yeeeep
>>59134046
I don't know what yield means but try just making a blank list and then pushing your results to that list instead of printing
>>59134046
I don't really know what it's meant to do, but shouldn't it be
else:
yield Gensubset(...)
>>59134119
>>59134046
https://jeffknupp.com/blog/2013/04/07/improve-your-python-yield-and-generators-explained/
read this to help you understand generators
you're doing it wrong