I am trying to write the lambda
based equivalent of Python functions as a learning exercise.
I have this working code, which takes a list and returns a new list with unique elements:
def unique_list(l):
x = []
for a in l:
if a not in x:
x.append(a)
return x
When I test it, I get the expected result:
>>> print(unique_list([1,1,1,2,2,3,3]))
[1, 2, 3]
But my attempt at replacing this with lambda
, as follows:
a = lambda l, x=[]:[x.append(a) for a in l if a not in x]
gives the wrong result:
>>> a([1,1,1,2,2,3,3])
[None, None, None]
What is wrong with the code?