Interview Query

Fill None Values

Start Timer

0:00:00

Upvote
9
Downvote
Save question
Mark as completed
View comments (29)
Next question

Given a sorted list of positive integers with some entries being None, write 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.

Example:

Input:

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

Output:

def fill_none(input_list) -> [1,2,2,2,4,5,5] 
.
.
.
.
.


Comments

Loading comments