[Solved] why are my python lambda functions not working?


.append() is an in place update, and returns None, so your current generator is creating a list of None which can’t be compared by sorted().

That aside, you don’t need to keep track of your newly split items with map() as it’s a generator that is being fed into sorted().

Try:

>>> my_list = ["a,a", "b,b", "c,c", "a,b"]
>>> sorted(map(lambda i: i.split(","), my_list))
[['a', 'a'], ['a', 'b'], ['b', 'b'], ['c', 'c']]

Or using a generator expression (my preferred method):

>>> my_list = ["a,a", "b,b", "c,c", "a,b"]
>>> sorted(i.split(",") for i in my_list)
[['a', 'a'], ['a', 'b'], ['b', 'b'], ['c', 'c']]

1

solved why are my python lambda functions not working?