Remove duplicates


#1

The solution is this:

def remove_duplicates(inputlist):
if inputlist == []:
return []

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[0]]

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.append(i)
    
return output list

In the third last line:
if i > outputlist[-1]:
how can you have an index in the negative range, can someone please explain what it means?


#2

never mind i got it, it means the latest element in the list


#3