Hello, I managed to solve this problem eventually but through my various attempts, I created a puzzling code( for me at least) and I do not understand why this set of code leads to the result stated

My Code:

def remove_duplicates(numbers):
  numbers_list = []
  for i in numbers:
    for y in numbers_list:
      if y == i:
        numbers_list = numbers_list
        numbers_list = numbers_list + [i]
  return numbers_list

After trying around with this code, I realized that the eventual result always leads to an empty list [] but I am unsure of how such a result came about from this code.
Please help!!! thank you :slightly_smiling_face:


Look at the line “for y in numbers_list” at this point the list is empty so the loop is never ran which is why you are returning an empty list

Remember that python has a condition “not in” that you can use


oh okay I understand now thank you!!!


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