using reverse in list of tuples
Marco Nawijn
nawijn at gmail.com
Thu Jun 10 04:41:16 EDT 2010
On Jun 10, 2:39 am, james_027 <cai.hai... at gmail.com> wrote:
> hi,
>
> 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?
>
> Thanks,
> James
As the others already mentioned list.reverse() is in-place, just as
for
example list.sort(). Alternatively, use the builtin reversed() or
sorted()
functions to get a return value (they will leave the original list
unmodified.
Example:
>>> a = range(3)
>>> b = reversed(a)
>>> for item in b:
...print item
This will produce:
2
1
0
Note that reversed returns an iterator.
Marco
More information about the Python-list
mailing list