How to reverse tuples in a list?

jon cashman joncashman_1967 at hotmail.com
Tue Aug 8 22:08:37 EDT 2006


sorry ... i replied to sender instead of all ... so here we go again ...

>>>t = [('a', 1.0), ('b',2.0),('c',3.0)]
>>>t = [s[::-1] for s in t]
>>>print t
[(1.0, 'a'), (2.0, 'b'), (3.0, 'c')]
>>>




>From: "Paul McGuire" <ptmcg at austin.rr._bogus_.com>
>To: python-list at python.org
>Subject: Re: How to reverse tuples in a list?
>Date: Wed, 09 Aug 2006 01:28:05 GMT
>
>"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')]
>
>
>--
>http://mail.python.org/mailman/listinfo/python-list

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/




More information about the Python-list mailing list