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

Is there any way to put an optional input into a function in the python version used here? (Problem set 3, problem 1) I created a function def countSubStringMatchRecursive(target, key, location=0) It keeps giving me errors

OpenStudy (vaboro):

did you put semicolon after function definition?

OpenStudy (vaboro):

you definition should have look like this: def countSubStringMatchRecursive(target, key, location=0): actually, your 'location' parameter is optional; however, if no argument is passed for 'location', the value 0 is used for it

OpenStudy (anonymous):

Hello Brownbear. I think I know what you mean - since I remember myself thinking about the same problem. Try putting the location in after find (inside the function itself... find(key,string,location) after as you're actually 'slicing' the string. - remember, we're looking for instances, not locations.

OpenStudy (anonymous):

Hey grupiyati. My location variable name references the location at which the search is done, because the find function works like find(target,string,[location to start working from]).

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!