you need to understand the difference between sorted() function and sort() method, e.g. list.sort() method
sorted() built-in function takes iterable and will return it sorted, i.e. you need to assign what it returns to a variable in order to use it later. it can be the same, e.g.
sorted() built-in function takes iterable and will return it sorted, i.e. you need to assign what it returns to a variable in order to use it later. it can be the same, e.g.
>>> a = [3, 1, 4, 2] >>> a = sorted(a) >>> a [1, 2, 3, 4]one possible use is to itreate over sorted iterable, without changing the original one
>>> a = [3, 4, 1, 2] >>> for item in sorted(a): ... print(item) ... 1 2 3 4 >>> a [3, 4, 1, 2]while sort() method will sort the iterable in place, e.g.
>>> a = [3, 1, 4, 2] >>> a.sort() >>> a [1, 2, 3, 4]