As Maniero commented, the logic of its function is somewhat obscure, since part of it functions as a filter, another as a map. They are conceptually distinct things that do different things.
When you use map
, a new sequence will be generated with the returned function indicated for each item in the original sequence. If the function does not return value, None
will be inferred, so these values appear in their final sequence.
With filter
, a new sequence will be generated with the values of the original sequence for which the indicated function returns a true value which, when dealing with numbers, will be any number other than 0. Thus, if you apply a filter and return x + x
, the final sequence will have the original value x
, because if x
is not zero, the x + x
value will also be nonzero and therefore true. The filter
function does not change the original values, it only filters.
So, what you need to do is separate the logics: first, filter your sequence with the desired values and then apply the map to modify them. If the intent is to remove odds less than 100, then:
filtrado = filter(lambda x: x >= 100 or x % 2 == 0, numeros)
That is, filtrado
will be a string with numeros
values that are greater than or equal to 100 or even. Now, just apply the map that doubles values greater than or equal to 100:
resultado = map(lambda x: x + x if x >= 100 else x, filtrado)
However, what map
returns (as well as filter
) are generators, not lists. If you want as lists, you need to do the conversion:
resultado = list(map(lambda x: x + x if x >= 100 else x, filtrado))
So the code would be:
>>> numeros = [100, 200, 1000, 3000, 2, 3, 4, 5, 6, 7, 8]
>>> filtrado = filter(lambda x: x >= 100 or x % 2 == 0, numeros)
>>> resultado = list(map(lambda x: x + x if x >= 100 else x, filtrado))
>>> print(resultado)
[200, 400, 2000, 6000, 2, 4, 6, 8]