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[
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
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
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]
>
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
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
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']
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
>