Oops, try again. remove_duplicates([4, 5, 5, 4]) resulted in an error: 'int' object has no attribute '__getitem__'
So with the [4,5,5,4] from the error, I would think that the
sorted() would change the input list to [4,4,5,5], (having learned in another Q&A that
.sort is not the right way to go, as it would return nothing.)
...then the output list would be initialized with the value 4. I've tried wrapping the initialization with
list() in order to specifically call out that I want 4 to be the beginning of a list, but it only creates a different error.
...then the loop would start through the input list and compare each input list value to the final value of the output list. So discard the initialized 4, the second 4, and when it arrives at the first 5, a-ha!, a value that is greater than 4, so append to output list.
...ignore the final 5, as it is not greater than the 5 just appended. Then return output list.
Thank you in advance.....I feel like I'm close here, but am missing an important distinction that I should be learning...
def remove_duplicates(inputlist): # Sort the input list from low to high inputlist = sorted(inputlist) # Initialize the output list, and give it the first value of the now-sorted input list outputlist = inputlist # Go through the values of the sorted list and append to the output list # ...any values that are greater than the last value of the output list for i in inputlist: if i > outputlist[-1]: outputlist = outputlist.append(i) return outputlist