On Aug 26, 9:47 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Mon, 25 Aug 2008 17:04:07 +0000, Grzegorz Staniak wrote: > > On 25.08.2008, Terry Reedy <[EMAIL PROTECTED]> wroted: > > >> The newish sorted() and reversed() built-ins were meant to complement > >> list.sort and list.reverse, not replace them. > > > BTW, is there a reason why sorted() on a list returns a list, while > > reversed() on the same list returns an iterator? > > Until the day that somebody discovers how to sort a list without seeing > all the items first, there's no point in sorted() returning an iterator.
To nitpick, this is not strictly true: sure, you're at best O(nlogn) on sorting the entire list, but you could return the first element of the 'sorted' list in O(n) (if you don't mind using a O(n^2) algorithm for the whole sort). i.e. if you have a use case where you're only likely to look at the first few elements of a sorted list, it would make some sense to have an iterator. -- http://mail.python.org/mailman/listinfo/python-list