If you really want to use lambda, you can do it with one lambda that issues the squared value or 0 depending on the oddness of the input, using a ternary expression (but you still have to filter using None so only non-zero numbers are kept)
nums = [1, 2, 3, 4, 5, 6]
result = list(filter(None,map(lambda n:n**2 if n%2 else 0,nums)))
result:
[1, 9, 25]
note that list conversion is required only for python 3.
Of course, all those filter, map, ... chaining renders the lambda inefficient/not that useful. You'd be better off with a simple list comprehension.
result = [n**2 for n in nums if n%2]
map should be only needed when you have the function (or built-in) handy (like map(str,my_list) for instance). All those chained calls could be less performant than that simple list comprehension in the end.
A more detailed explanation here: https://docs.python.org/2/howto/functional.html#small-functions-and-the-lambda-expression
Which alternative is preferable? That’s a style question; my usual course is to avoid using lambda.
One reason for my preference is that lambda is quite limited in the functions it can define. The result has to be computable as a single expression, which means you can’t have multiway if... elif... else comparisons or try... except statements. If you try to do too much in a lambda statement, you’ll end up with an overly complicated expression that’s hard to read.
[1, 9, 25]?[ num * num for num in nums if num % 2 == 0 ][ num * num for num in nums if num % 2 != 0 ]mapandfilterwith non-builtin functions, and you should instead use the equivalent comprehsion construct.