How to reverse tuples in a list?

Paul McGuire ptmcg at austin.rr._bogus_.com
Tue Aug 8 21:28:05 EDT 2006


"Noah" <noah at noah.org> wrote in message
news:1155081671.728757.228050 at p79g2000cwp.googlegroups.com...
> I have a list of tuples
>     [('a', 1.0), ('b', 2.0), ('c', 3.0)]
> I want to reverse the order of the elements inside the tuples.
>     [(1.0,'a'), (2.0, 'b'), (3.0, 'c')]
>

>>> tups =  [('a', 1.0), ('b', 2.0), ('c', 3.0)]
>>> map(tuple,map(reversed,tups))
[(1.0, 'a'), (2.0, 'b'), (3.0, 'c')]





More information about the Python-list mailing list