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

reading behind from list

import numpy as np

filename = 'input1.txt'
output_file = 'output.txt'
delimiters = ',.?!'

with open(filename, 'r') as f:
    text = f.read()
for delimiter in delimiters:
    text = text.replace(delimiter, ',')
lines = text.split('\n')
parts = list()
print(lines)

I want all the lines containing text / numbers from the back to be in the sheet

example I have an input.text file

1,2,3,4,5,6
7,8,9,10,11,12
13,14,15,16,17

this give me

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

['1,2,3,4,5,6', '7,8,9,10,11,12', '13, 14,15,16,17 ',' ',' ',' ', '', '', '', '', '']

I’m looking for an exit from behind to read the lines

['13, 14,15,16,17', '7,8,9,10,11,12', '1,2,3,4,5,6', '', '', '', '', '', '', '']

Thank you for your help

>Solution :

Reverse a list in Python:

print(list('abc')[::-1])
> ['c', 'b', 'a']

Your case:

import numpy as np
import re
filename = 'input1.txt'
output_file = 'output.txt'
text = re.sub('[.?!]', ',', text)

with open(filename, 'r') as f:
    text = f.read()
text = re.sub('[.?!]', ',', text)

lines = text.split('\n')[::-1]
parts = []
print(lines)
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