list.reverse()

Paul McGuire ptmcg at austin.rr.com
Tue Apr 29 10:26:07 EDT 2008


On Apr 28, 1:12 pm, Mark Bryan Yu <vaf... at gmail.com> wrote:
> This set of codes works:
>
> >>> x = range(5)
> >>> x.reverse()
> >>> x
>
> [4, 3, 2, 1, 0]
>

You can also use list slicing to get a reversed list:

>>> x = range(5)
>>> x
[0, 1, 2, 3, 4]
>>> x[::-1]
[4, 3, 2, 1, 0]

-- Paul



More information about the Python-list mailing list