Created function to sort list of tuples