<filename>strings/mutations.py<gh_stars>0
""" Read a given string, change the character at a given index and then print the modified string.

Input:-
abracadabra
5 k

Output:-
abrackdabra

Hackerank Link: https://www.hackerrank.com/challenges/python-mutations/problem """

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

if __name__ == "__main__":
    import doctest

    s = input()
    """
    >>> string = "abracadabra
    >>> l = list(string)
    """

    i, c = input().split()
    """
    >>> l[5] = 'k'
    >>> string = ''.join(l)
    """

    s_new = mutate_string(s, int(i), c)
    """
    >>> print string
    """
    print(s_new)

    doctest.testmod()

<filename>strings/mutations.py<gh_stars>0
""" Read a given string, change the character at a given index and then print the modified string.

Input:-
abracadabra
5 k

Output:-
abrackdabra

Hackerank Link: https://www.hackerrank.com/challenges/python-mutations/problem """

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

if __name__ == "__main__":
    import doctest

    s = input()
    """
    >>> string = "abracadabra
    >>> l = list(string)
    """

    i, c = input().split()
    """
    >>> l[5] = 'k'
    >>> string = ''.join(l)
    """

    s_new = mutate_string(s, int(i), c)
    """
    >>> print string
    """
    print(s_new)

    doctest.testmod()

Read a given string, change the character at a given index and then print the modified string.  Input:- abracadabra 5 k  Output:- abrackdabra  Hackerank Link: https://www.hackerrank.com/challenges/python-mutations/problem >>> string = "abracadabra     >>> l = list(string) >>> l[5] = 'k'     >>> string = ''.join(l) >>> print string