I am working on remove_duplicates in Practice Makes Perfect. Here's my code:
def remove_duplicates(ls): #Create New Empty List new_list =  for i in range(len(ls)): if ls.count(ls[i]) > 1: new_list.append(ls[i]) if new_list.count(new_list[i]) > 1: new_list.remove(new_list[i]) return new_list
When I run this I receive the following error:
Oops, try again. remove_duplicates([4, 5, 5, 4]) resulted in an error: list index out of range
I'm confused as to why my list index is out of range, and which part of my code is causing the error. I've already solved this using an if val not in list > append to new list; I thought I'd try it this way but now I'm struggling.
I appreciate any assistance, thanks!