Help understanding the decisions *behind* python?
Niels L. Ellegaard
niels.ellegaard at gmail.com
Mon Jul 20 18:39:24 EDT 2009
Phillip B Oldham <phillip.oldham at gmail.com> writes:
> We often find we need to do manipulations like the above without
> changing the order of the original list, and languages like JS allow
> this. We can't work out how to do this in python though, other than
> duplicating the list, sorting, reversing, then discarding.
If you just want a one-liner, and you don't care about speed you can
do the following (but I don't think this is considered best practice)
>>> x = [2,1,3]
>>> print list(sorted(x))
[1, 2, 3]
>>> print x
[2, 1, 3]
Niels
More information about the Python-list
mailing list