I'm on problem set 6 trying to find all subsets of letters in hand. I found and implemented itertools successfully, but I haven't been able to write my own code that does the same thing. I'm basically looking at the itertools.combinations code and trying to mimick what it's doing without the yeild function, since the course hasn't covered it yet. If you run my code you can see where it goes wrong from the print statements, but I can't spot how the itertools.combinations code is solving the problem. code here: http://pastebin.com/keQzLrXU
what's up with this syntax? shouldn't else be indented? Valid statement in Python, I agree with you that is rather unusual ( http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops)
Concerning the yield keyword, pretty new for me, I found a clear (as clear as possible) explanation here: http://stackoverflow.com/questions/231767/the-python-yield-keyword-explained
just because something hasn't been covered in lecture doesn't mean you can't use it. this isn't a Python class, it is a CompSci and Programming class that uses Python. If you find something useful in the language, use it. worked for me. http://dpaste.com/696593/
wow. It took me an incredible amount of time to understand the itertools.combinations code. Thanks for pointing me to the python documentation maitre -- 4.4 shows you can use else to close off a for loop. Weird. I've worked out some code that uses the same method minus the yield function, plus some handy print statments to make clear what's going on inside: http://pastebin.com/JaKLFt8y . bwCA: I understand it's a CS class and not a Python class, but isn't that a reason to complete the excercises without using python functions that haven't been dicussed in the lectures? With that said, I am a little frustrated that there was nothing discussed in the lectures that helps solve the subsets problem. There was plenty on sorting, so that part of the exercise was feasible, but there is NO WAY I could have come up with the above pasted code on my own based on just the lectures and reading materials.
Six3, Remember that the class was designed for MIT students. It wasn't designed for a youtube audience so there probably are gaps. That's part of the tradeoff of a free class. With that said, I think the subset problem can be solved with what's been taught through lecture 10. I don't think one needs to use itertools.
Join our real-time social learning platform and learn together with your friends!