As others mentioned tuples are immutable. Sorting a tuple (e.g. sorted(mytuple)
) returns a list, which you would then have to cast back to a tuple.
To sort a tuple (and keep it a tuple) you'd have to do this:
mytuple = (3,2,1)
mysortedtuple = tuple(sorted(mytuple))
To sort a list you'd have to do this:
mylist = [3,2,1]
mylist.sort()
Because you're not casting and re-casting, the latter, in this instance, is more efficient.
Don't get hung up on using tuples over lists unless you have a good justification. If you need sorted data, tuples are not the way to go unless they are created that way in the first place. Tuples excel when the data they contain DOES NOT CHANGE, such as with configuration settings that are loaded at run-time, or data that has already been processed.
Considering that you mentioned you are processing a large dataset, you might want to look at using a functional programming style by way of generators and iterators over lists and tuples. This way you're not shuttling around and creating new containers, but just chaining iteration operations to get to the end result.
Further reading: