14/15


#1
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 outputlist
print remove_duplicates([-23, 234, 234, 345, 345]) 

CAN ANYONE PLEASE MAKE ME UNDERSTAND-

if i > outputlist[-1]:
            outputlist.append(i)

#2

we can access items in a list by index from the left side of the list, like so:

the_list[1]

but we can also access from the right hand side of the list, using negative indexes, so [-1] is the last value in the list:

the_list = ['a', 'b', 'c']
print the_list[-1] # output: c

so the if comparison check if i is greater then last value in list, if so, append to list given its not yet in the list.


#3

thanks a ton, its a new concept for me.