Sortable Software Versions

Hard ⏱ 18 min 38% acceptance ★★★★★ 4.8
Implement Version(major, minor, patch) with __eq__ and __lt__ comparing the three numbers lexicographically, decorated with functools.total_ordering so <=, >, >= come free. A list of Versions must sort correctly with plain sorted().

Examples

Example 1
Input
Version(1, 10, 0) > Version(1, 9, 9)
Output
True
Explanation

Numeric tuple comparison: 10 beats 9 in the minor slot.

Constraints

  • Use @total_ordering.
  • Define only __eq__ and __lt__ yourself.

Topics

OOPcomparison dunders

Companies

GitHubAtlassianJetBrains

Hints

Hint 1

Compare (major, minor, patch) tuples.

Hint 2

from functools import total_ordering.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.