I am trying to join an underscore into a string, but when running the code I get 4 times the character i used
str = potetoBox

for indx in range (len(str)):
    if str[indx].isupper():
        #split before indx and input an underscore
        str = ''.join((str[:indx],'_',str[indx:]))

print(str)

I have tried to change characters and change the order of the code. I expected to get only one underscore.

When using join in a string, I get too many characters in the string
Another solution without re that doesn't build a list:
result = ""
for c in my_str:
    result += "_" * c.isupper() + c

