Python Sorted Function Time Complexity