I am trying to learn recursion. I am trying to take a list as a parameter and return a new list in which the values that were in the old list appear only once in the new list.
I have been going at this for hours but keep getting stuck.
I am trying to learn recursion. I am trying to take a list as
Share
Notice that new_list will always be empty at this point, so this condition will always be true and all elements will be added to the new list.
Your code is one little tweak away from functioning correctly. Instead of checking if the item is in the new_list, I think you should be checking if it’s in the rest of the old list: