How to fill elements between intervals of a list

后端 未结 6 2331
无人及你
无人及你 2021-02-14 18:19

I have a list like this:

list_1 = [np.NaN, np.NaN, 1, np.NaN, np.NaN, np.NaN, 0, np.NaN, 1, np.NaN, 0, 1, np.NaN, 0, np.NaN,  1, np.NaN]

So the

6条回答
  •  花落未央
    2021-02-14 18:39

    Here's a code where a variable replace will determine if the element should be replace or not and for will iterate from 0 to len of the interval and if it finds 1 then replace will true then elements will be replaced and when it will find next 0 replace will be falls and element will not replace till again appearing of 1

      replace = False
        for i in (len(interval)-1):
            if interval[i]==1:
                replace = True
            elif interval[i]==0:
                replace = False
            if replace:
                list[i]=inerval[i]
    

提交回复
热议问题