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 to remove second word with a line break form array

How can remove 2.50\n from this array?

line = ['1.60\n2.50\n2.15', '1.80\n2.20\n1.90']

Tried with split, rsplit but I can’t remove

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

I need result to be
line = ['1.60\n2.15', '1.80\n1.90']
Can regex do it?

>Solution :

If the number that you want to remove from the string is not always the same you can use something like:

new_line = []
for entry in line:
    lst = entry.split('\n')
    lst.pop(1)
    entry = "\n".join(lst)
    new_line.append(entry)
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