Think Python: How to Think Like a Computer Scientist

(singke) #1
>>> t2  =   t[:]
>>> t2.sort()
>>> t
[3, 1, 2]
>>> t2
[1, 2, 3]

In this example you could also use the built-in function sorted, which returns a new,
sorted list and leaves the original alone:


>>> t2  =   sorted(t)
>>> t
[3, 1, 2]
>>> t2
[1, 2, 3]
Free download pdf