Sorting function practice in python