How Can I Sort A Portion Of A List In Place?
Possible Duplicate: Python: sort a part of a list, in place I want to implement a decision tree algorithm, and my implementation calls for sorting the table in order attribute b
Solution 1:
This is sort-of inplace. It does require temporary storage for the sorted part
>>> a=range(20,0,-1)
>>> a
[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
>>> a[10:15]=sorted(a[10:15])
>>> a
[20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 6, 7, 8, 9, 10, 5, 4, 3, 2, 1]
>>>
Post a Comment for "How Can I Sort A Portion Of A List In Place?"