A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • 5 years ago

ps3c.py... it looks like subStringMatchExact needs to match an empty string to... something... or subStringMatchOneSub doesn't work when substituting the first or last letter. What should it say for the occurrence of an empty string in "ATGACATGCACAAGTATGCAT"?

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

    Can you rephrase your question I don't understand what you're asking.

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

    subStringMatchOneSub (the code provided in the lecture) calls the methods we're supposed to write. It calls our method, subStringMatchExact, looking for instances of the string "" in various other strings. This causes my method for subStringMatchExact to go into an infinite loop, and so I got no answer. Changing subStringMatchExact to return an empty tuple (no matches) does not work either. My constrainedMatchPair method looks logically correct but may be wrong, I supppose... here's a dpaste of the code: http://dpaste.com/532155/

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

    Your substring match exact should only take two arguments. You don't have to change it if you don't want to I don't think it affects your code but what the pset said was to only use 2 arguments. Also I don't know what I am supposed to be checking because I just ran this on my computer and it didn't get stuck in a loop? What version of python are you using?

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

    It's a recursive solution. Because default values are provided for the last two, only needle and haystack (key and target) need to be provided to invoke the function. I don't believe it would be possible to solve this recursively (which was an option) with just two arguments, but I could be wrong. I added the condition needle == "" to the base case to get around the infinite loop, but it still doesn't return the right answer. If you look at the output, subStringMatchOneSub splits key into "ATG" and "" at the end. Match1 finds ATG at position 0. But because match2 is empty, 0 doesn't make it into the allAnswers tuple. It should, though, because the string starting at 0 (ATGACA...) matches "ATGC" with one substitution. Is there something wrong with my constrainedMatchPair method? I think I implemented it according to the instructions, but it will never return a match if one of the tuples that's passed to it is empty. If you run this with different arguments (like "ATCA", "ATGACATGCACAAGTATGCAT") the code works as it should. There is a match at position 0 because "ATCA" matches "ATGA" except that the C is replaced with G. The problem is, this doesn't happen when the first or last letter of "key" is removed.

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

    First since there default values there would be no difference if you assigned them in the first 2 lines of your function but like I said you don't have to change it there will be no difference except following the prompt. Give me one sec on checking your constrained matchPair function I'm not the best at recursive functions so it might take me a little while.

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

    Here this one works the reason you were getting an empty tuple back for it was you were saying if needle=="" return occurences but remember your occurences were originally set to () so it just returned (). so I made the if needle=="" into a separate if and told it to return a tuple with numbers 0 through length of list. I don't know if this was the best way to do this like I said before I'm not good with recursive functions but this was the only way I could think to do it. http://dpaste.com/hold/532230/

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

    Ah! Thank you. That seems to work. Inelegant and kind of counterintuitive, but I was kind of suspecting that was what I needed. Thanks, Onyx.

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

    Yea no problem

  9. 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.