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

hey guys .. i have a hard time understanding problem 3 on pset3 anybody care to explain ??

OpenStudy (anonymous):

You have to write a function such that it will take as input a tuple of starting points of matches in the first substring (let it be X), and a tuple of starting points of matches in the second substring (let it be Y), and you have to return a tuple of N elements in X such that each i-th element in N obeys the rule, for some M in Y: N[i] + length(substring_one) + 1 = M.

OpenStudy (anonymous):

sorry but matchs of what >> where is the strings ??

OpenStudy (anonymous):

am i supposed to use the function i wrote in problem 2??

OpenStudy (anonymous):

Yes, matches of the pattern to the string, i.e. 'test test test', 'test', should return (0,5,10) from the function written previously, and it should be one of the parameters to the new function.

OpenStudy (anonymous):

thank you ... or like we say in arabic "shukran"(:

OpenStudy (anonymous):

ahlan wa sahlan, if my memory does not fail me :-)

OpenStudy (anonymous):

HAHAH you're good(:

OpenStudy (anonymous):

i'm really ignorant in this problem sorry but i don't understand the eqution "n+m+1=k" i tried to run it but it's all wrong ..here's the code: def matchpair (one,two,length): tuple = () for m in one: for n in two: if m +1+len(one)==n: tuple+=(m,) continue continue return tuple

OpenStudy (anonymous):

I will avoid rigor here for simplicity's sake: Your intuition is right, as you have to muscle out both tuples passed as arguments, you will need a double nested loop. Why are you using continues? Avoid using tuple as a name for a variable, it's a keyword in Python. Another note, post your code in codepad to make your code more readable. Here: http://codepad.org/7yL9KOSn

OpenStudy (anonymous):

i think i discovered the mistake i will print the code after a "shukran again"

OpenStudy (anonymous):

the code i've written works with strings missing an element from the middle like:'abde' missing the'b' = 'a de' but when i try it on :"abd" missing the"e" ='abd ' it doesn't work ??

OpenStudy (anonymous):

never mind i got it (:

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!