Answers for "python remove middle of string"

0

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"))
Posted by: Guest on October-20-2021

Code answers related to "python remove middle of string"

Python Answers by Framework

Browse Popular Code Answers by Language