On Aug 22, 1:35 pm, John Machin <[EMAIL PROTECTED]> wrote: > On Aug 22, 12:12 pm, "++imanshu" <[EMAIL PROTECTED]> wrote: > > > Hi, > > > Is there a reason why two similarly named functions Sorted and > > Reversed return different types of data or is it an accident. > > You seem to have an interesting notion of "similarly named". > name0[-2:] == name1[-2:], perhaps? The two functions (eventually, in > the case of "reversed") return data in the order one would expect from > their names. > > >>> x = [1, 3, 5, 2, 4, 6] > >>> sorted(x) > [1, 2, 3, 4, 5, 6] > >>> reversed(x) > > <listreverseiterator object at 0x00AA5550> > > > > >>> list(reversed(x)) > [6, 4, 2, 5, 3, 1]-
Sorry; having re-read the message subject: reversed came later; returning an iterator rather than a list provides more flexibility. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list