3 ms·
> you seem to be implying that only recursive algorithms are idiomatic in Python. He didn't say that, so thankfully there's nothing to disagree with.
by DougBTX 15y ago
> you seem to be implying that only recursive algorithms are idiomatic in Python.
He didn't say that, so thankfully there's nothing to disagree with.
- baddox 15y agoRe-read what he said. It's a pretty clear implication that recursive code is idiomatic in Python.
- prodigal_erik 15y agoSome algorithms solve a problem by examining solutions to other instances of the same problem. Minimax and quicksort work this way, as do a lot of tree and graph traversal problems. Implementations of these algorithms are inherently recursive, in the sense that you're going to need to say "carry out the whole algorithm again here". You can always fake recursion by creating objects to hold the state of the call graph (or stack, if you don't have continuations), but that's so cumbersome to write or read that you'll quickly be better off in a language that doesn't force you to do it, just as we've now all adopted languages which actually provide functions rather than faking it by saving and restoring variables around GOTOs (I wish I were kidding).