A running length resets when a sequence breaks. Watch what happens at a missing observation.
length = 0
for observation in [4, 8, None, 2]:
if observation is None:
length = 0
else:
length += 1
print(length)
# 1
# 2
# 0
# 1The current length and the longest length can differ. Keep both when looking for a record-length spell.
Implement longest_frost(values). Values are temperature numbers or None, in time order. Return the length of the longest uninterrupted run of temperatures strictly below zero. A missing value or a temperature of zero or above breaks a run. Return zero if no frosts occur.
longest_frost([-2, -1, None, -4, 0, -3]) # 2