Open this example in the interactive library
Source code
from math import isfinite
print([n for n in [1, float('nan'), float('inf'), -2] if isfinite(n)])Sample output
[1, -2]

Open this example in the interactive library
from math import isfinite
print([n for n in [1, float('nan'), float('inf'), -2] if isfinite(n)])[1, -2]