Felix Collins wrote:
> Hi All,
> does anyone know any cleaver tricks to sort a list of outline numbers.
For 2.4 and beyond: (using a key function)
def numparts(outlinetext):
return [int(number) for number in outlinetext.split('.')]
lst = ['1', '1.2', '1.12', '1.1', '3.1']
lst.sort(key=numparts)
For 2.3: (using DSU -- Decorate, Sort, Undecorate)
def numparts(outlinetext):
return [int(number) for number in outlinetext.split('.')]
lst = ['1', '1.2', '1.12', '1.1', '3.1']
decorated = [(numparts(txt), txt) for txt in lst]
decorated.sort()
lst[:] = [txt for code, txt in decorated]
--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list