This may seem elegant, but I’m afraid this would be to slow on large lists. Another elegant solution uses the fold operator.
First define a function that adds an element to a list if it does not already belong to it :