Converting a three-dimensional version string to a single float won't give you numbers that you can compare meaningfully in all cases. Consider the versions:
3.15.1
3.7.4
3.7.3
2.20.5
If you simply ignore the second period, you end up with:
3.151
3.74
3.73
2.205
which breaks the ordering.
If you represent these as tuples, e.g.:
(3, 15, 1)
(3, 7, 4)
(3, 7, 3)
(2, 20, 5)
they'll sort correctly, as shown here:
>>> versions = ["3.7.3", "3.15.1", "3.7.4", "2.20.5"]
>>> [tuple(map(int, v.split("."))) for v in versions]
[(3, 7, 3), (3, 15, 1), (3, 7, 4), (2, 20, 5)]
>>> max(tuple(map(int, v.split("."))) for v in versions)
(3, 15, 1)
and if you want to turn it back into a string at the end:
>>> ".".join(map(str, max(tuple(map(int, v.split("."))) for v in versions)))
'3.15.1'
or use the key
argument to max
to simply do the conversion in-place at the time the comparisons are made:
>>> max(versions, key=lambda v: tuple(map(int, v.split("."))))
'3.15.1'