[Skip]
> If s.reverse() is dumped shouldn't s.sort() be as well?
I don't think so. When you run reversed(s), the s argument
can be any Sequence (either mutable or immutable) and the
return value is an iterator that doesn't copy the whole
dataset.
In contrast, sorted() takes any iterable and makes a full
copy of it before sorting it.
So reversed(s) can be done without doubling memory
consumption (and is just as fast as iterating forward),
but sorted() is a much heavier operation.
Since reversed() and sorted() were introduced, I've almost
never had occasion to want list.reverse() but I still use
list.sort().
One other reason for keeping list.sort() is that sort
stability lets you make multiple passes:
mylist.sort(key=attrgetter('name')
mylist.sort(key=attrgetter('score', reverse=True)
# Now, it's sorted by reverse score, then alphabetically.
There's not a parallel use case for successive reverses.
Raymond
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe:
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com