Skip to content
Advertisement

Sorting and Re-formatting a text file

Need help with the following:

  1. Reading from one string until another specified string.
  2. Merging 2 strings on separate lines onto 1 line I tried strip() and this was not successful.
  3. Create 2 separate arrays from the text provided.

Given:

JavaScript

Desired output:

JavaScript

These sentences are separated because they will be put in an array.

JavaScript

Final output:

JavaScript

Here is my code:

JavaScript

Advertisement

Answer

Try this:

JavaScript

It will output:

JavaScript

This assumes that a grouping always contains ‘Chores’, action is always 1 word, and outputs a string of a dictionary. My version doesn’t separate ‘Get dog food.’ and ‘Walk Dog.’ but if you want that you can add a split() on ‘. ‘ and handle it. The formatting of your input data is horrible and really shouldn’t be used as is.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement