tjreedy at udel.edu
Sat Nov 15 02:29:38 CET 2003
"xam" <ma at Bell.com> wrote in message
news:8ubtb.171852$pT1.82030 at twister.nyc.rr.com...
> std::sort - works on any well-ordered object collection (you just
> your own operator< if you need to sort based on some weird criteria)
List.sort works whenever the contents are inter-comparable, which is
possibly more often with Python than with C. It takes an optional
compare function and in 2.4 will probably take an optional key
function arg. This will be will be called O(n) instead of O(nlogn)
times (as with compare functions). Its n outputs will then be
compared as usual. List is the only linear non-lazy mutable builtin,
so a sort function rather than method would make no sense. Classes
derived from list inherit .sort().
When possible, Python functions (and for loops) work generically with
iterables rather than specifically with lists.
Terry J. Reedy
More information about the Python-list