list.reverse()
Diez B. Roggisch
deets at nospam.web.de
Tue Apr 29 10:48:19 EDT 2008
>
> The reasoning goes along the lines of, "reverse in place is an expensive
> operation, so we don't want to make it too easy for people to do". At
> least that's the gist of what I got out of the argument the many times it
> has come up.
It's not about the storage - it is about the in-place-modification. The
reasioning is that people otherwise could assume that
a = [1, 2]
b = a.reverse()
assert a[0] == 1 and b[0] == 2
would hold, but instead of course "a" is changed.
Using reversed as
b = reversed(a)
will make that assumption hold.
Diez
More information about the Python-list
mailing list