Suppose I have the following list in Python:
my_list = [10] * 95
Given n
, I want to replace any other m
elements with zero in my list, while keeping the next n
elements.
For example, if n = 3
and m = 2
, I want my list to look like:
[10, 10, 10, 0, 0, 10, 10, 10 ,0, 0, ..., 10, 10, 10 , 0, 0]
If it can't be filled perfectly, as is the case with n = 4
and m = 2
, then it's OK if my list looks like this:
[10, 10, 10, 10, 0, 0, ..., 10, 10, 10, 10, 0]
How should I try to solve this problem?