Quantcast
Channel: One of many recursive calls of a function found the correct result, but it can't "tell" the others. Is there a better fix than this ugly workaround? - Stack Overflow
Browsing latest articles
Browse All 5 View Live

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 Article


Answer 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 Article


Answer 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 Article

Answer 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 Article

One 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

Browsing latest articles
Browse All 5 View Live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>