If the data is read 3 times in a row, then the next data changes value by 20 data

I want to make a change if the randomList data produces a value of 0 three times in a row and then it will change the randomList value to 1 for the next 20 data and here’s an example of a random program that I made.

import random
randomlist = []
for i in range(0,100):
    n = random.randint(1,20)
    if n > 10 :
        randomlist.append('0')
    else :
        randomlist.append('1')
    
print(randomlist)

I’m sorry I made changes to the data, to make it easier to understand my question.

dataList = [4, 9, 10, 12, 5, 6, 15, 16, 8, 18, 20, 21, 1, 3, 5, 6, 8, 15, 13, 22, 25, 1, 3, 11, 5, 18, 24, 25, 23, 19, 14, 6, 9, 3, 20, 3, 1, 20]
result=[]
for i in dataList:
    if i > 10 :
        result.append('0')
    else :
        result.append('1')

Here are the results

['1', '1', '1', '0', '1', '1', '0', '0', '1', '0', '0', '0', '1', '1', '1', '1', '1', '0', '0', '0', '0', '1', '1', '0', '1', '0', '0', '0', '0', '0', '0', '1', '1', '1', '0', '1', '1', '0']

Desired result

['1', '1', '1', '0', '1', '1', '0', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', '1', '0', '1', '1', '0']

Answer

If i understand you right, you want to add 20 zeros to your list if the previous 3 elemenst were zero. Here i check the last three elements, and add zero 20 times then pass the next 20 iterations.

dataList = [4, 9, 10, 12, 5, 6, 15, 16, 8, 18, 20, 21, 1, 3, 5, 6, 8, 15, 13, 22, 25, 1, 3, 11, 5, 18, 24, 25, 23, 19, 14, 6, 9, 3, 20, 3, 1, 20]
result=[]
one_before = now = None
i = 0
for item in dataList:
    try:
        if dataList[i] > 10 : 
            result.append('0')
        else :
            result.append('1')
    except:
        break  

    two_before = one_before     # the two element before the last element
    one_before = now     # one element before the last element 
    now = result[-1]     # value of the last element
    zero_list = ['0']*20    # List containing 20 zeros to append result 

    if now=='0' and one_before=='0' and two_before=='0':  #Check if last three elements are zero
        result.extend(zero_list)  # Add 20 zeros 
        i = i+21    # Pass 20 iterations
    else:
        i = i+1     # Pass to next iteration

print(result)