anonymous
  • anonymous
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"?
MIT 6.00 Intro Computer Science (OCW)
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
Can you rephrase your question I don't understand what you're asking.
anonymous
  • anonymous
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/
anonymous
  • anonymous
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?

Looking for something else?

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

More answers

anonymous
  • anonymous
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.
anonymous
  • anonymous
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.
anonymous
  • anonymous
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/
anonymous
  • anonymous
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.
anonymous
  • anonymous
Yea no problem

Looking for something else?

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