Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 Online
OpenStudy (anonymous):

I'm working on 2008 PS #6, question 4... Basically it's asking to generate all combinations of subsets out of string of n length... (not just sets, since repeated elements are allowed) so for 'word' [w,o,r,d,wo,wr,wd,or,od,rd,wor,wod,wrd,ord,word] I'm not sure if I can import something to help, or if that's 'cheating', and I should be able to come up with something from 'scratch'!?!??

OpenStudy (anonymous):

Not to answer my own question... but this is what I came up with using imported combinations from itertools... but I'm not sure this isn't cheating?? Did I do the assignment or weasel out of it??? Is it like being asked to use a sort function, but just using list.sort() instead??? http://dpaste.com/925338/

OpenStudy (anonymous):

If it's asking you for code, I would think you should write your own. If it's asking for just the combinations, writing your own code and testing it is proof (in my mind) that you know what's going on. If your doing the problems for credit I would check with your prof.

OpenStudy (anonymous):

Fair enough... but I can't seem to come up with anything from scratch that will work on any length input... Any ideas?

OpenStudy (anonymous):

damn that is tough. why do the 2008 ones tho? the notes dont match up

OpenStudy (rsmith6559):

FWIW, my play_hand() is about 35 lines of code, and I don't have any code for permutation in it.

OpenStudy (anonymous):

after using itertools and looking at various solutions on the web i tried to tackle it myself and came up with this - http://dpaste.com/932089/

OpenStudy (anonymous):

Wow bwCA... that certainly works, but it uses concepts I'm not familiar with yet... I found this code, which also works... though I'm not sure exactly how it works... http://dpaste.com/933416/

OpenStudy (anonymous):

string formatting: http://docs.python.org/2.7/library/string.html#formatstrings list comprehensions are just a shorthand way of writing a for loop that builds a list: http://docs.python.org/2.7/reference/expressions.html#list-displays

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!