Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python remove middle of string

def remove_middle_character(s):
    h = len(s)//2
    mod = (len(s) + 1) % 2
    return s[:h - mod] + s[h + 1:]

if __name__ == "__main__":
    print(remove_middle_character(""))
    print(remove_middle_character("x"))
    print(remove_middle_character("xy"))
    print(remove_middle_character("apple"))
    print(remove_middle_character("banana"))
    print(remove_middle_character("discount"))
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #remove #middle #string
ADD COMMENT
Topic
Name
7+6 =