Mutations

  • + 0 comments

    Solution #2

    def mutate_string(string, position, character):
        
        # Slice the string and join it back (quicker but harder to visualize)
        '''
    The string is sliced into two parts:
    string[:position]: from the start of the string up to (but not including) the position index.
    string[position+1:]: from the character right after the position index until the end of the string.
    
    We process to put the character between the parts
        '''
        s_new = string[:position] + character + string[position+1:]
        
        return s_new
    
    if __name__ == '__main__':
        s = input()
        i, c = input().split()
        s_new = mutate_string(s, int(i), c)
        print(s_new)