How to reverse tuples in a list?
Robert Kern
robert.kern at gmail.com
Tue Aug 8 20:08:41 EDT 2006
Noah wrote:
> 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')]
Python 2.4+:
y = [tuple(reversed(t)) for t in y]
--
Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
More information about the Python-list
mailing list