I have a need to sort a list of elements that represent sections of a
document in dot-separated notation. The built in sort does the wrong thing.
This seems a rather complex problem and I was hoping someone smarter than me
had already worked out the best way to approach this. For example, consider
the following list-
[color=blue][color=green][color=darkred]
>>> foo[/color][/color][/color]
['1.0', '1.0.1', '1.1.1', '1.2', '1.9', '1.10', '1.11', '1.20', '1.20.1',
'1.30'][color=blue][color=green][color=darkred]
>>> foo.sort()
>>> foo[/color][/color][/color]
['1.0', '1.0.1', '1.1.1', '1.10', '1.11', '1.2', '1.20', '1.20.1', '1.30',
'1.9']
Obviously 1.20.1 should be after 1.9 if we look at this as dot-delimited
integers, not as decimal numbers.
Does anyone have pointers to existing code?
document in dot-separated notation. The built in sort does the wrong thing.
This seems a rather complex problem and I was hoping someone smarter than me
had already worked out the best way to approach this. For example, consider
the following list-
[color=blue][color=green][color=darkred]
>>> foo[/color][/color][/color]
['1.0', '1.0.1', '1.1.1', '1.2', '1.9', '1.10', '1.11', '1.20', '1.20.1',
'1.30'][color=blue][color=green][color=darkred]
>>> foo.sort()
>>> foo[/color][/color][/color]
['1.0', '1.0.1', '1.1.1', '1.10', '1.11', '1.2', '1.20', '1.20.1', '1.30',
'1.9']
Obviously 1.20.1 should be after 1.9 if we look at this as dot-delimited
integers, not as decimal numbers.
Does anyone have pointers to existing code?
Comment