Apr-11-2020, 10:48 PM
Hello, I must do the following task: Write a recursive function ajouter(element, set) which returns a set (represented by a list) to which a new element has been added (if it does not already belong to the set). Do not use the keyword "in".
I already started this program but I have a problem for when I have to return the function: I lose the starting set.
Thank you for the answer
Cyril from France
I already started this program but I have a problem for when I have to return the function: I lose the starting set.
def ajouter(element, ensemble): if ensemble==[]: ensemble.append(element) return ensemble else: if ensemble[0]==element: return ensemble else: return ajouter(element, ensemble[1:]) element=4 ensemble=[1,2,3]Can you help me please ?
Thank you for the answer
Cyril from France