Logo

Programming-Idioms

History of Idiom 19 > diff from v17 to v18

Edit summary for version 18 by :

Version 17

2015-10-29, 14:05:12

Version 18

2015-10-31, 16:25:55

Idiom #19 Reverse a list

Reverse the order of the elements of list x .
This may reverse "in-place" and destroy the original ordering.

Idiom #19 Reverse a list

Reverse the order of the elements of list x .
This may reverse "in-place" and destroy the original ordering.

Code
x = x[::-1]
Code
x = reversed(x)
Comments bubble
This creates a new list.
Comments bubble
returns an iterable.
on lists this creates a new list.
Doc URL
https://docs.python.org/3/library/functions.html#reversed
Origin
http://stackoverflow.com/a/3940137/871134
Origin
http://stackoverflow.com/a/3940137/871134