Solution to sort list