How to reverse tuples in a list?
Sion Arrowsmith
siona at chiark.greenend.org.uk
Wed Aug 9 10:11:08 EDT 2006
Robert Kern <robert.kern at gmail.com> wrote:
>Python 2.4+:
>
> y = [tuple(reversed(t)) for t in y]
>
Python 2.3:
y = [ t[::-1] for t in y ]
Obviously works in 2.4 as well, where I make it faster than using
tuple(reversed(t)). Which isn't surprising, as it's not constructing
the intermediate list.
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list