Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How i can remove only one letter from a text if it has multiple

How i can remove letter from the position

string1 = 'BPBPBPPPBPPPPPPBBBBPPBPBPPBPPPPBBPBPPBPBPP'
letter_4 = string1[3]
new_text = re.sub(letter_4,'', string1)

The resault is BBBBBBBBBBBBBBBB

The result I want is to remove only the letter number 4, which is ‘P’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As Carlos Horn said in his comment, to remove a character at index n in a string, you can simply use

st = "Hello there"
n = 6
st = st[:n]+st[n:]

In this case specifically:

string1 = 'BPBPBPPPBPPPPPPBBBBPPBPBPPBPPPPBBPBPPBPBPP'
n = 3
new_text = string1[:n]+string[n+1:]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading