'How to reduce my execution time in python when i am using print function?

So, When i am using print()/sys.stdout.write() to print my results (I have checked all the results are correct) the program execution time is increasing to min of 100times when i was not using print.

N = Number of elements in lists(numpy array)
C = C is an element of array
T = Number of Arrays

1≤N≤1000
1≤Ci≤10^5
1≤T≤100

I am thinking this is happening because of print function. If yes How would I solve this issue
Without Print Execution time = 0.012797699999999967
With Print Execution time = 1.1667817

This is a question From Google KickStart



def sub_one(inputlist, inputlength):
    smalllist = np.array([], dtype='int32')
    outputlist = np.array([], dtype='int32')
    h_score = 1
    for mainnum in inputlist:
        if mainnum > h_score:
            smalllist = np.append(smalllist, mainnum)
        else:
            outputlist = np.append(outputlist, mainnum)
            continue
        eachlist = np.array([], dtype='int32')
        for num in smalllist:
            if num >= h_score:
                eachlist = np.append(eachlist, h_score)
                if np.count_nonzero(eachlist) == h_score:
                    outputlist = np.append(outputlist, h_score)
                    smalllist = smalllist[smalllist > h_score]
                    h_score += 1
    

    return outputlist





def caseprinter(thelist):
    returnstring = ""
    for i in thelist:
        returnstring += (str(i) + " ")
    return returnstring



if __name__ == "__main__":
    cases = int(input())
    for i in range(cases):
        inputlength = int(input())
        inputlist = input().split(" ")
        inputlist = np.array(inputlist, dtype='int32')
        outputlist = sub_one(inputlist, inputlength)
        print(f'Case #{i+1}: {caseprinter(outputlist)}')```


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source