Answer by Quack E. Duck for One of many recursive calls of a function found...
Since refactoring the traverse function to be iterative instead of recursive was discussed in the comments, here is that version too for completeness' sake:# Iterative-only version of the same function...
View ArticleAnswer by Kelly Bundy for One of many recursive calls of a function found the...
I'd write it differently, using the result of the recursive calls to decide whether to return immediately or continue searching. My version returns a non-empty list of indices if the item was found, or...
View ArticleAnswer by user1196549 for One of many recursive calls of a function found the...
You need to stack the indexes as you go, and assign the recursive function a success flag. When you perform a recursive call, you push the new index. When the function returns, in case of failure you...
View ArticleAnswer by Nick for One of many recursive calls of a function found the...
Your first attempt is almost perfect, the only mistake is that you return the result of searching through the first list/tuple at the current depth, regardless of whether the item was found or not....
View ArticleOne of many recursive calls of a function found the correct result, but it...
Recently, I was experimenting with writing a function to find a primitive value anywhere within an arbitrarily deeply nested sequence, and return the path taken to get there (as a list of indices...
View Article