Mutations

Sort by

recency

|

1092 Discussions

|

  • + 0 comments

    def mutate_string(string, position, character): return string[:position]+character+string[position+1:]

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

  • + 0 comments
    list1=list(string)
    del list1[position]
    list1.insert(position,character)
    string=''.join(list1)
    return string
    
  • + 0 comments

    I passed all test cases on submiting or running the code for a few seconds and then it fails reverting with a Runtime Error: Traceback (most recent call last): File "/tmp/submission/20250121/02/01/hackerrank-fcae3a6b8a4ebd2191a0a3e1614f0f2d/code/Solution.py", line 11, in s = input() ^^^^^^^ EOFError: EOF when reading a line

    I tried catching the error but it still fails. Any Solutions?

    This is the code: def mutate_string(string, position, character): return string[:position] + character + string[position + 1:]

    if name == 'main': try: s = input().strip() i, c = input().split() s_new = mutate_string(s, int(i), c) print(s_new) except EOFError: pass

  • + 0 comments
    return string[:position] + character + string[position+1:]
    
  • + 0 comments

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

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