Skip to main content
Code Review

Return to Revisions

2 of 3
added 506 characters in body
J_H
  • 41.7k
  • 3
  • 38
  • 157

nested functions

Nested functions aren’t doing you any favors in this case. Place them up at top level, please, where they are accessible to other callers, such as unit tests.

doctest

Show us example input and output in the docstring, please. Use "python -m doctest *.py" to verify.

generalize

DRY is sometimes called "the rule of three". So this code isn’t exactly too repetitive.

Nonetheless, the problem statement trivially generalizes from a pair of input strings to N inputs. Consider solving the general problem, at least as far as pre-processing each input string goes. When faced with N inputs, you will be forced to loop over them. I feel this would result in somewhat cleaner code, even for the 2 input case.

zip

I was a little surprised to not see zip() tuples being fed to max() or some custom helper function.

annotations

Typically you should just be annotating the signatures, please. It's a bit crazy to annotate all those assignments instead. If mypy can't figure out the type of what you assigned, then you probably want to add a --strict switch to it, and more carefully annotate the function(s) being called. The biggest situation where assignment annotations win is when you initialize some empty container, so we can't yet see the type of what it will hold, e.g. words: list[str] = [].

J_H
  • 41.7k
  • 3
  • 38
  • 157
default

AltStyle によって変換されたページ (->オリジナル) /