May-17-2018, 12:25 PM
Removing the chatterbot part (just interested in the input parser):
with open('chats.txt','rt') as fd: conv = [] last = '' for line in fd: # Remove newline and whitespaces only from the end of the line line = line.rstrip() if line.startswith(' '): last += line else: if last: conv.append(last) last = line # Add the final string... last will be '' ony if the file is empty if last: conv.append(last) for k, line in enumerate(conv): print(f"{k}: {line}")The result is:
Output:0: What are some common warning signs of stress and/or depression in men?
1: General signs of stress: Fast heart rate Muscle tension Increase in blood pressure Tense stomach
2: Long-term signs of stress: Frequent cold or flu Headaches Trouble sleeping Skin problems Digestion problems Poor concentration Negative thoughts Speech problems Anxiety Irritability Feelings of helplessness Poor eating Being accident prone Aggression.
So as you can see, only 3 lines (some of them really long) If you see it better, the conv array is:[ 'What are some common warning signs of stress and/or depression in men?', 'General signs of stress: Fast heart rate Muscle tension Increase in blood pressure Tense stomach', 'Long-term signs of stress: Frequent cold or flu Headaches Trouble sleeping Skin problems Digestion problems Poor concentration Negative thoughts Speech problems Anxiety Irritability Feelings of helplessness Poor eating Being accident prone Aggression.' ]You might need to improve the punctuation and format (i.e. there are many double spaces in the strings)