[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Alright python noob here, too lazy to post it on stack overflow.

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 10
Thread images: 2

File: py.png (80KB, 1000x1000px) Image search: [Google]
py.png
80KB, 1000x1000px
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
>>
File: 1481974723165.jpg (183KB, 1260x1024px) Image search: [Google]
1481974723165.jpg
183KB, 1260x1024px
>>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
Thread posts: 10
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.