using reverse in list of tuples

rantingrick rantingrick at gmail.com
Wed Jun 9 21:06:23 EDT 2010


On Jun 9, 7:39 pm, james_027 <cai.hai... at gmail.com> wrote:
>
> I am trying to reverse the order of my list of tuples and its is
> returning a None to me. Is the reverse() function not allow on list
> containing tuples?


list.revese() is an in-place operation! don't try to assign the return
value back to your list!

>>> lst = [(x, x+1) for x in range(5)]
>>> lst
[(0, 1), (1, 2), (2, 3), (3, 4), (4, 5)]
>>> lst.reverse()
>>> lst
[(4, 5), (3, 4), (2, 3), (1, 2), (0, 1)]



More information about the Python-list mailing list