Interview Query

Fill None Values

Have you seen this question before?

Given a sorted list of positive integers with some entries being None, create a function to return a new list where all None values are replaced with the most recent non-None value in the list.

Note: If the first entry in the list is None, assume the previous entry was 0.



input_list = [1,2,None,None,4,5,None]


def fill_none(input_list) -> [1,2,2,2,4,5,5] 
Next question: Statistically Significant Test
Python 3.9.6
Loading editor
Use Shift + Enter to run code