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

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')
    entry = "\n".join(lst)

Leave a Reply