As by your comments, float
is not the datatype you need. In your case, you have an actual hierarchy of chapters/sections.
One simple (and remember, simple is better than complex) way is to represent the section numbers as tuples. Since tuples are sorted lexicographically, they naturally sort in the desired order:
>>> lf = [(1, ), (1, 1), (1, 10), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (2, ), (1, 9)]
>>> sorted(lf)
[(1, ), (1, 1), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (2, )]
As we can see, this also works for tuples with varying lengths.
If want to keep the sections as strings, natsort does a fine job of handling dotted values, too:
>>> s = ['1', '1.1', '1.10', '1.2']
>>> natsort.natsorted(s)
['1', '1.1', '1.2', '1.10']
You can also define your own SectionNumber
class, but that's probably overkill.