lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp
Xah Lee
xahlee at gmail.com
Thu Mar 1 00:39:37 EST 2012
On Feb 29, 9:01 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> You don't need a temporary variable to swap two values in
> Python. A better way to reverse a list using more Pythonic idioms is:
>
> for i in range(len(list_a)//2):
> list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i]
forgive me sir, but i haven't been at python for a while. :)
i was, actually, refreshing myself of what little polyglot skills i
have.
Xah
More information about the Python-list
mailing list