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

python : how to split the non-numeric character in lists?

I am trying to work out a simple function to split lists.

Here is one example list that i am working on

list

'Internet Specific                          163  23.42   163  23.45   5401.44  30.78 \n'

After I applied strip() and split function, i got this result.

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

list.strip().split()
['Internet', 'Specific', '163', '23.42', '163', '23.45', '5401.44', '30.78']

But, I want to split the list like this.

['Internet Specific', '163', '23.42', '163', '23.45', '5401.44', '30.78']

I want to split the numeric value but not the alphabet. Is there any way?

Thanks in advance

>Solution :

You can use python re module and re.split() to split string.

Pattern used: \s+(?=\d) [This search for one or more whitespace before digit]

Code:

import re
data = 'Internet Specific                          163  23.42   163  23.45   5401.44  30.78'
result = re.split("\s+(?=\d)", data)

print(result)

Output:

['Internet Specific', '163', '23.42', '163', '23.45', '5401.44', '30.78']
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