So I have a few list comprehensions that look like the following.
li = [some_computation(x) for x in y if some_computation(x)]
Where I only want the values that are truthy with respect to some_computation.
- Does this compute
some_computation(x)twice as the list comprehension makes it seem? Ifsome_computationis expensive, I really don't want this. (I feel like this is probably the case:() - Is there a better way to do this? Perhaps to break it into a regular for loop and append if only if
some_computation(x), but I like comprehensions.