I want to call a method and add the returned value to a list only if the value is not None, in place.
Approach 1
list = []
for item in items:
temp = func(item)
if temp is not None:
list.append(temp)
Approach 2
[func(item) for item in items if func(item) is not None]
The first approach is more verbose than I want but accomplishes my goal. The second approach is in place, but requires two calls to func(item). If possible I would like to reuse the first call in a var that I then use in the comparison.
Not proper python but in the vein of what I am looking for
[(a = func(item)) for item in items if a is not None]