Remove Duplicates - Confused


I know this isn’t the most elegant code, but I felt it should work. What am I doing wrong here?

def remove_duplicates(x):
  dup = []
  new = []
  final_list = dup + new
  for i in x:
    if x.count(i) > 1:
  return final_list


ok nvm i solved it - I was over thinking :joy:

def remove_duplicates(x):
  list = []
  for i in x:
    if i not in list:
  return list


Just a side note, list is a built in function, and even though this is a local variable it is still better that we avoid using it, or any other function names or reserved words.


Good point - thanks!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.