#algorithm #python #language #programming #efficiency
-
Sort
andsorted
in python are to organize elements in a specific order -
They have two
keywords
:key
andreverse
- key: receive a function with one argument to be pass the element to be compared to other: High Order Functions
- reverse: if the order is reversed
-
Sort
does not return a new object while butsorted
returns, so the former isin-place
, in that way less memory is used. - Sorted objects are faster to be searched by any algorithm
Warning
For immutable objects like Python Tuples sort need to return a new object because the object is not mutable or no changeable.
References
Ramalho, 2022, p56-58