I wrote the following code to remove duplicates from a list:
def remove_duplicates(listy):
new_listy = []
for i in range(len(listy)):
a = listy.pop(i)
while a in listy:
listy = listy.remove(a)
else: new_listy.append(a)
return new_listy
The following error is given when running the code:
Traceback (most recent call last):
File "<pyshell#93>", line 1, in <module>
remove_duplicates([1,1,2,2])
File "C:\Python27\MIT_4.py", line 4, in remove_duplicates
a = listy.pop(i)
AttributeError: 'NoneType' object has no attribute 'pop.
What is causing this error? How can it be fixed to solve this correctly?