<jupyter_start><jupyter_text>**Write a method to replace all the spaces in a string with `%20`. You may assume that the string has sufficient space at the end to hold the additional characters and that you are given the “true” length of the string.**Input: `"<NAME>", 13`Output: `Mr%20John%20Smith`Input: `"<NAME>   ", 13`Output: `Mr%20John%20Smith` https://stackoverflow.com/questions/31087111/typeerror-list-object-is-not-callable-in-python/31087151<jupyter_code>example = list("abc gh")
example
s =''.join(example)
s
# O(N)
# edit the string backwards so we don't worry about
# overwriting characters

def urlify(string, length):
    newIndex = len(string)
    string = list(string)
    for i in reversed(range(length)):  # start with the last char of the string
        if string[i] == ' ':
            string[newIndex - 3: newIndex] = '%20' 
            newIndex -= 3
        else: 
            string[newIndex-1] = string[i]
            newIndex -= 1
    return ''.join(string)
urlify('much ado about nothing      ', 22) # 'much%20ado%20about%20nothing'
urlify('Mr <NAME>    ', 13) # 'Mr%20John%20Smith'<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13081650570676032, 'fraction_numerical': 0.043898156277436345, 'mean_word_length': 3.6341463414634148, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '353959', 'license': 'MIT', 'n_tokens_mistral': 409, 'n_tokens_neox': 363, 'n_words': 110, 'path': 'notebooks/ch1_arrays_and_strings/1.3 URLify.ipynb', 'repo_name': 'Julyzzzzzz/Practice-on-data-structures-and-algorithms', 'size': '1157'}