Question: Python Programming I am suppose to write a program function removeDuplicate that given a list removes and returns any repeated items from a list
Python Programming
I am suppose to write a program function "removeDuplicate" that given a list removes and returns any repeated items from a list so that each item appears at most once.
- For instance, the list [1,1,2,3,4,3,0,0] would become [1,2,3,4,0].
My source code is as follows:
def removeDuplicate(lst):
lst.sort()
for i in range(len(lst)-1):
if lst[i] == lst[i+1]:
lst.pop(i)
return lst
I keep getting an "IndexError: list index out of range"
I have tried changing the range value using len(lst), len(lst)+1, len(lst)+2 and even len(lst)-2 just to see the result. But same error message keeps popping up.
Please what am I doing wrong. I would gladly appreciate if you can send me a pic of a proper run of the removeDuplicate function as well if you can.
Thanks..
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
