Sorted Returns List and Reversed Returns Iterator
John Machin
sjmachin at lexicon.net
Thu Aug 21 23:35:55 EDT 2008
On Aug 22, 12:12 pm, "++imanshu" <himanshu.g... at gmail.com> 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]
>>>
More information about the Python-list
mailing list