timeit.timeit(
    """responses = list(r)
while responses and isnan(responses[-1]): responses.pop()"""
    ,
    'from math import isnan; nan = float("nan"); r = [1.0, nan, 9.0, nan, nan, nan, nan, nan, nan, nan, nan]'
    )
timeit.timeit("""responses = list(r)
responses = responses[:3]""",
    'from math import isnan; nan = float("nan"); r = [1.0, nan, 9.0, nan, nan, nan, nan, nan, nan, nan, nan]'
    )
Python: remove repeated values only if at end of list