Search
 
SCRIPT & CODE EXAMPLE
 

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"))
Comment

PREVIOUS NEXT
Code Example
Python :: find no of iterations in python 
Python :: tkinter mouse loading cursor 
Python :: google translate english to spanish 
Python :: Reason: "broken data stream when reading image file" in jupyter notebook 
Python :: onetomany field 
Python :: seaborn plot to see outliers 
Python :: How to change the height of an input in python tkinter 
Python :: nlargest of each group 
Python :: mak a scipy csr sparse matrix 
Python :: max sum slice python 5 - autopilot 
Python :: python allow null argument 
Python :: what is python virtual environment 
Python :: imshow show nan as black 
Python :: plt force axis numbers 
Python :: simple example of printing a C version of a SymPy expression: 
Python :: Scopes and Namespaces Example in python 
Python :: quicksort python 
Python :: python download progress bar 
Python :: unique items in a list python 
Python :: re.split 
Python :: if else condition python 
Python :: python function to multiply two numbers 
Python :: pygame python 
Python :: fizz buzz fizzbuzz python game 
Python :: math in python 
Python :: optional arguments python 
Python :: get dataframe name python 
Python :: Getting the data type 
Python :: if we use list in the dictionary 
Python :: data type 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =