An alternative way to speed up sorts is to construct a list of tuples whose first element is a sort key that will sort properly using the default comparison, and whose second element is the original list element. Suppose, for example, you have a list of tuples that you want to sort by the n-th field of each tuple. The following function will do that. String Concatenation Strings in Python are immutable. This fact frequently sneaks up and bites novice Python programmers on the rump.
Immutability confers some advantages and disadvantages.
In the plus column, strings can be used a keys in dictionaries and individual copies can be shared among multiple variable bindings. Instead, you have to create a new string with the desired properties. This continual copying can lead to significant inefficiencies in Python programs. The former is a very common and catastrophic mistake when building large strings. This is a lot faster, and easier to modify also.