Mutations

Sort by

recency

|

1083 Discussions

|

  • + 0 comments
    def mutate_string(string, position, character):
        # mutate string (slicing and joining)
        updated_string = string[:position]+ character + string[position+1:]
        return updated_string
        
    
    if __name__ == '__main__':
        s = input()
        i, c = input().split()
        s_new = mutate_string(s, int(i), c)
        print(s_new)
    
  • + 0 comments
    def mutate_string(string, position, character):
        return "".join(character if i == position else c for i, c in enumerate(string))
    
  • + 0 comments
    def mutate_string(string, position, character):
        string=list(string)
        string[position]=character
        string="".join(string)
        return string
    
    if __name__ == '__main__':
        s = input()
        i, c = input().split()
        s_new = mutate_string(s, int(i), c)
        print(s_new)
    
  • + 0 comments

    def mutate_string(string, position, character): string=list(string) string[position]=character string="".join(string) return string

    if name == 'main': s = input() i, c = input().split() s_new = mutate_string(s, int(i), c) print(s_new)

  • + 0 comments
    def mutate_string(string, position, character):
    s = string
    i = position
    c = character
    list(s)
    
    return s[:i] + c + s[i+1:]
    
    if __name__ == '__main__':
    s = input()
    i, c = input().split()
    s_new = mutate_string(s, int(i), c)
    print(s_new)