31 ms·
I think the problem of list comprehension is that it is not as flexible as combination of map() and filter(). For example, [F(x) for x if P(x)] is equivale
by riobard 18y ago
I think the problem of list comprehension is that it is not as flexible as combination of map() and filter(). For example,
[F(x) for x if P(x)]
is equivalent to
map(F, filter(P, S))
but what about the equivalence of
filter(P, map(F, S))?
Without using any map() and filter(), this is the solution came up to my mind
[x for x in [F(y) for y in S] if P(x)]
Pretty ugly, huh?
- bamsjakalaka 18y ago[F(x) for x in S if P(F(x))]
- riobard 18y agoThat means you have to do F(x) TWICE, which is sometimes ineffective (when F(x) costs too much)