A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 4 years ago

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

  • This Question is Closed
  1. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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)

  2. maitre_kaio
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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

  3. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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/

  4. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  5. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  6. anonymous
    • 4 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    http://dpaste.com/697083/

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.