Need help with the following:
- Reading from one string until another specified string.
- Merging 2 strings on separate lines onto 1 line I tried strip() and this was not successful.
- Create 2 separate arrays from the text provided.
Given:
Cat Chores
Get
cat food.
Dog Chores
Get
dog food. Walk Dog.
Desired output:
Cat Chores
Get cat food.
These sentences are separated because they will be put in an array.
Dog Chores
Get dog food. Walk Dog.
Final output:
cat_chores = [Get cat food.]
dog_chores = [Get dog food. , Walk Dog]
Here is my code:
# Remove whitespace and reformat the file
with open('chores.txt',"r") as f:
text = input.read()
text = [lines.strip() for lines in text]
with open('chores.txt',"w") as f:
f.writelines(text)
f.close
# Re-open the file to create the arrays.
with open('chores.txt',"r") as f:
text = input.read()
if "Cat Chores" in text:
print (line,end='')
print(next(input),end='')
if "Dog Chores" in text:
print (line,end='')
print(next(input),end='')