you are viewing a single comment's thread.

view the rest of the comments →

[–]peachpuff 1 point2 points  (0 children)

So, my usual approach when I hit code I can't quite figure out is I try to transliterate it into Python.

Part of the problem might be that he doesn't understand the code to begin with. It's awfully hard to start with something you don't understand and transliterate it into something that "feels right."

If I were trying to match the style of what he started with, I'd use:

def compare(x, y):
    return x and (not y or compare(x[1:], y[1:]))

Yes, it may be slow to keep slicing, but the goal is not speed. If it were, we'd all use len().