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

why cant i put this tuple in my function? I'm confused def subStringMatchExact(target, key): match = () for index in range(0, len(target) -1): match += (index,)

OpenStudy (anonymous):

My understanding is that you can not append a tuple, BUT you can overwrite the tuple entirely. So you could use: match = match[:] + (index,) That worked for me. Also, I don't think you should be using a range that goes up to len(target)-1. What if your key is one character, or even two characters, long?

OpenStudy (anonymous):

if you want a tuple with those values in it you could do this: match = range(len(target)-1) match = tuple(match) the range function returns a list, then turn it into a tuple

OpenStudy (anonymous):

im still confused because this one works: x = 10 divisors = () for i in range(1, x): if x%i == 0: divisors = divisors + (i,) and mine doesnt work even though they look exactly the same except mine is in a function...

OpenStudy (anonymous):

Hey I think your code should run without a hitch. I even ran your code(along with a return statement) on IDLE. The code returns all but the last of the indices of target.

OpenStudy (anonymous):

but i dont see any results from the tuple when i enter strings in the parameters the shell just gives me another <<< blank line with no tuple printed, (i have a print statement on there now btw)

OpenStudy (anonymous):

The attached file is the code that I used (which seems to work). Check it out.

OpenStudy (anonymous):

i also tried your code and it works, here is what i got in idle one function returns match, the next prints match as it is being made: http://dpaste.com/553417/ you won't see anything in idle unless you return something from the function

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!