Leetcode Medium Level Arraylist Sort Function In Python