Python: Tuples and Sorting Data
The tuple
A tuple is very similar to a list, the only difference is that a tuple can't be changed.
We make tuples by using regular brackets instead of square brackets, for example:
TupleOne = (99, 12, 61, 64)
Tuples cannot be changed once created.
Sorting data
We can sort lists, and strings using sort methods (tuples cannot be sorted as they have to stay the same after they are made).
Lists can simply be done by typing the list's name, followed by a full stop, followed by sort (with no arguments) - For example:
ListOne = [99, 21, 62, 22, 71] ListOne.sort() ListOne
We can also sort strings, but since strings dont actually have a ".sort()" method, we have to use "sorted". We can just output the sorted string like so:
StringOne = "Fred" sorted(StringOne)
Or we can actually set it to the sorted order:
StringOne = "Fred" StringOne = sorted(StringOne)
Back to Python

