RE: HELP:sorting list of outline numbers

2005-08-03 Thread Delaney, Timothy (Tim)
Scott David Daniels wrote: > Delaney, Timothy (Tim) wrote: >> Scott David Daniels wrote: >>> For 2.3: (using DSU -- Decorate, Sort, Undecorate) > ... >>> lst = ['1', '1.2', '1.12', '1.1', '3.1'] >>> decorated = [(numparts(txt), txt) for txt in lst] >>> decorated.sort() lst[

Re: HELP:sorting list of outline numbers

2005-08-03 Thread Christopher Subich
Felix Collins wrote: > Using Decorate, Sort , Undecorate... > > works like a charm. As a one-liner, you can also deconstruct and rebuild the outline numbers: new_outline = ['.'.join(v) for v in (sorted([k.split('.') for k in old_outline]))] -- http://mail.python.org/mailman/listinfo/python-list

Re: HELP:sorting list of outline numbers

2005-08-03 Thread Scott David Daniels
Delaney, Timothy (Tim) wrote: > Scott David Daniels wrote: >>For 2.3: (using DSU -- Decorate, Sort, Undecorate) ... >> 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 decorate

RE: HELP:sorting list of outline numbers

2005-08-02 Thread Delaney, Timothy (Tim)
Scott David Daniels wrote: > 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] >

Re: HELP:sorting list of outline numbers

2005-08-02 Thread Felix Collins
Felix Collins wrote: > > Thanks Scott and Robert for your quick help. This list is amazing! > > Regards, > Felix Using Decorate, Sort , Undecorate... works like a charm. Thanks again. Felix -- http://mail.python.org/mailman/listinfo/python-list

Re: HELP:sorting list of outline numbers

2005-08-02 Thread Felix Collins
Robert Kern wrote: > Felix Collins wrote: > > Use the "key" keyword argument to list.sort(). > > In [1]: outline = ['1.12', '1.1', '1', '1.2'] > > In [2]: outline.sort(key=lambda x: map(int, x.split('.'))) > > In [3]: outline > Out[3]: ['1', '1.1', '1.2', '1.12'] > Is this new in 2.4? I hav

Re: HELP:sorting list of outline numbers

2005-08-02 Thread Scott David Daniels
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']

Re: HELP:sorting list of outline numbers

2005-08-02 Thread Robert Kern
Felix Collins wrote: > Hi All, > does anyone know any cleaver tricks to sort a list of outline numbers. > > An outline number is a number of the form...1.2.3 > > they should be sorted in the following way... > > 1 > 1.1 > 1.2 > 1.12 > > python's alpha sort (by design) sorts them... > > 1 >

HELP:sorting list of outline numbers

2005-08-02 Thread Felix Collins
Hi All, does anyone know any cleaver tricks to sort a list of outline numbers. An outline number is a number of the form...1.2.3 they should be sorted in the following way... 1 1.1 1.2 1.12 python's alpha sort (by design) sorts them... 1 1.1 1.12 1.2 That's no good for me. I'm planning on