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

I'm working on PS3, part 3. I can't say I understand the question. Can anyone help me out? The problem states "Write a function (called constrainedMatchPair) which takes three arguments: a tuple representing starting points for the first substring, a tuple representing starting points for the second substring, and the length of the first substring. The function should return a tuple of all members (call it n) of the first tuple for which there is an element in the second tuple (call it k) such that n+m+1 = k, where m is the length of the first substring."

OpenStudy (anonymous):

Apparently I'm verbose; my question wouldn't fit in the space provided. So here's the rest of it. So is this correct? n= a tuple representing starting points for the first substring, k= a tuple representing starting points for the second substring, m= the length of the first substring. If anyone has completed this part of the PS3 set, could you please post it?

OpenStudy (anonymous):

I also haven't written that function, because misunderstanding of the problem. I was trying all evening to understand that problem, but I didn't get it. I think if anyone explains you the problem in little simpler way, you will get it. Here is solution for all problem sets, from one of the member of this study group: http://proficiamus.blogspot.com

OpenStudy (anonymous):

you are correct, JulieNewbie, about constrainedMatchPair arguments for each element in n is there an element in k that meets the equation. if there is, then 'save' this (n) element. when you are done checking all the elements in n, return all the elements that were 'saved'

OpenStudy (anonymous):

I'm having the same issue here. I don't understand what this function is supposed to return.

OpenStudy (anonymous):

I can tell you what it's supposed to return. You're trying to find near-matches to your key string inside of the target string. So you break the key into two parts (key1 and key2), search for those, then use the equation n+m+1 = k to find near-matches of the entire key. Then you report these near-matches by printing a tuple of the starting indices of each near-match inside of the target. So an example would be match ATGC against ATGACATGCACAAGTATGCAT You can see that the firs 4 indices of the target are "ATGA" which is the same as the key except it has one substitution. So you would create a list to save "0" because the near-match starts at index 0. You add to this list all the starting points of other near-matches, which would spit out [0, 5, 15] for this example. ( I think... I did it by looking at it as opposed to running the script I haven't written yet...)

OpenStudy (anonymous):

Something else I'm hung up on is this: they say in the assignment to report tuples. However, tuples are immutable, so how in the world can I iterate through the string & keep track of the answers? Seems to me the only option is to create a list.

OpenStudy (anonymous):

use the tuple function to turn the list you have been working with into a tuple return tuple(myList)

OpenStudy (anonymous):

O. M. G. It's that easy??? What would I do without this study group?

OpenStudy (anonymous):

i really don't know what the consequences are, i/we haven't been working with very large data sets. but it is so easy to change data types back and forth, if i need to do something i look for methods in other data types and see if i can make it work.

OpenStudy (anonymous):

Interesting. I read somewhere (in the readings for this class) that mutable lists leave your code vulnerable to malware, so tuples would be more secure. However, if the data types are so easy to change, then it wouldn't matter anyway.

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!