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

I am trying ps 6 and I am stuck in problem 4. I don't know how to find all the subset of a string, can anyone tell me?

OpenStudy (maitre_kaio):

When I read that question, I was a bit afraid too. Then I thought that this problem had probably been solved by someone else. And I was right: in Python, you can use the itertools library to solve this kind of problems: http://docs.python.org/library/itertools.html#module-itertools And that's how I used it: http://pastebin.com/L42X6DP6

OpenStudy (anonymous):

Thank you maitre_kaio

OpenStudy (anonymous):

i just found another cool one, it is hard to parse but it looks like implements the algorithm listed in the wikipedia powerset entry http://dpaste.com/694742/

OpenStudy (anonymous):

Is it the point to just find a tool that does the work you want?How deeply should you understand how each works? I cannot tell from the pset wording.Seems you could just find an example or previous tool/module to do whatever you like without really knowing the innards.I do that to some extent but feel like I am missing the basics.

OpenStudy (anonymous):

i like to understand all that i can. at least one of the 'lessons' for this pset is to show how different data types can affect execution and how pre-processing data can affect execution. Itertools.combinations and permutations were not available when this course was taught - but everyone taking the course could have easily searched the internet or the library for algorithms. Never hurts to try it yourself and learn something doing it.

OpenStudy (anonymous):

Maitre_kaio, I have a similar piece to yours but why do you need .join?I am using itertools.combination on a the list,current_hand, is your 'word' a string?Seems the results from each result of itertools will be a string which can be appended to the list,letter_combinations.OK,tell me what I am doing and thinking incorrectly. http://codepad.org/IpGN88Sr

OpenStudy (anonymous):

@gambit did you read the documentation for itertools.combination?

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!