with open('text.txt') as file:
text = file.read()
text = text.replace('\n', ' ')
s = text.split('CATEG:')
s = [x.strip() for x in s if x != '']
print(s)
with open('mydata.txt') as f:
for line in f:
line = line.strip(' \t\r\n') # remove spaces and line endings
if line.ednswith(';'):
pass # this is category definition
else:
pass # this is data line