Model artefacts get version strings like "1.4.2" — major, minor, patch. Sorting them is where people get caught, because sorting them as text is wrong: alphabetically, "1.10.0" comes before "1.9.0", since the character 1 sorts before 9. A deploy script that trusts that will happily roll out an older model as the newest one.
The fix is to compare the parts as numbers.
Task: write sort_versions(versions) returning the versions ordered newest first.
"major.minor.patch".., convert each part to an integer, and compare the triples. Major decides first; minor only breaks a tie on major; patch only breaks a tie on both.Python compares lists element by element, so once you've turned "1.10.0" into [1, 10, 0] the comparison you want is the one you get for free. That's the whole trick: convert to a shape whose default ordering is already correct, rather than writing the comparison yourself.