A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
Problem with a recursive approach to problem set 2 question 2 (ps3b).
anonymous
 5 years ago
Problem with a recursive approach to problem set 2 question 2 (ps3b).

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I always end up with the function yielding nested tuples, plus I could not do it without passing an additional arg. to the function to keep the length of the sliced string. http://dpaste.com/531825/ Any ideas?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Sorry, this question is in regards to problem set 3, not 2

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I don't understand recursive functions enough to explain them but I can give you mine if you want it and you can try to figure it out?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0that'll be great, thanks

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0to solve the nested tuple problem, instead of returning loc, subStringMatchRecursive(target,key,(loc+1)) you return things like loc + subStringMatchRecursive(target,key,(loc+1)) when you use a comma, even without parens it assumes your trying to make a tuple, or at least it does sometimes, its sketchy at best. when you use the "+", tried to create one whole thing. sometimes the tuple doesn't like to add with a non tuple, when that happens i find that you can help it along by putting the non tuple variable (say x) tuple + (x,) hopefully that made sense and i understood what was going wrong

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Like Nessman said, you can fix your code by returning: (loc,) + subStringMatchRecursive(target,key,(loc+1)) You'll also have to seed an empty tuple instead of None, which is what you're implicitly seeding (by not having a return outside the while loop). You can do that by adding "return tuple()" outside your while loop. I've attached my ps3b.py for reference. I solved it three different ways, but my "subStringMatchExact2" is closest to your code.
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.