I came across the question Python - Removing duplicates in list only by using filter and lambda, where the OP asks how to remove duplicate elements from a Python list using exclusively filter
and lambda
functions.
This made me wonder, is it possible, from a theoretical point of view, to remove the duplicates from a Python list using only lambda
functions?
If so, how can we do that?
In this case, "removinge the duplicates" means "keeping exactly one occurrence of each element present in the original list", so [1,2,1,3,1,4]
should become [1,2,3,4]
.
In addition, the goal is to write only one lambda
, so the code would be a one-liner like:
lambda l: """do something that returns l without duplicates"""
No external variable must be used.
Besides, as for the above question, nothing "fancy" is allowed, especially the set
function, as well as reduce
, map
...
Basically, no other function, even the built-in, should be called.
lambda a: list(set(a))
?? – wwii