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,)
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?
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
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...
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.
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)
The attached file is the code that I used (which seems to work). Check it out.
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
Join our real-time social learning platform and learn together with your friends!