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

Delete first(s) and last(s) non letter characters from string in Python

I need some help trying to delete non letter characters from strings in python (specifically, column names) but only the ones at the beggining and the end of the string.

Here it is so you can understand better what I am dealing with:

column_names = ['Column_1', 'Column_2_', '_Column_3__', '__Column_4___']

I need the output to be like this:

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

column_names = ['Column_1', 'Column_2', 'Column_3', 'Column_4']

Can you help me please?

>Solution :

You can do something like this ?

for i in range(0,len(column_names)):
    column_names[i] = column_names[i].strip("_")

Strip also works if you specify which chars you want to strip (doc).

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