Re: How to reverse tuples in a list?
- From: Erik Max Francis <max@xxxxxxxxxxx>
- Date: Tue, 08 Aug 2006 17:03:17 -0700
Noah wrote:
But it seems like there should be a clever way to do this with
a list comprehensions. Problem is I can't see how to apply
reverse() to each tuple in the list because reverse() a
list method (not a tuple method) and because it operates
in-place (does not return a value). This kind of wrecks doing
it in a list comprehension. What I'd like to say is something like
this:
y = [t.reverse() for t in y]
Even if reverse worked on tuples, it wouldn't work inside a
list comprehension.
Why would you want to do it with list comprehensions? Use reversed:
>>> t = (1, 2, 3)
>>> u = tuple(reversed(t))
>>> u
(3, 2, 1)
--
Erik Max Francis && max@xxxxxxxxxxx && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
The quickest way of ending a war is to lose it.
-- George Orwell, 1903-1950
.
- Follow-Ups:
- Re: How to reverse tuples in a list?
- From: Robert Kern
- Re: How to reverse tuples in a list?
- References:
- How to reverse tuples in a list?
- From: Noah
- How to reverse tuples in a list?
- Prev by Date: How to reverse tuples in a list?
- Next by Date: Re: Class data being zapped by method
- Previous by thread: How to reverse tuples in a list?
- Next by thread: Re: How to reverse tuples in a list?
- Index(es):
Relevant Pages
|