I do not know python. I'm not going to provide code. I'll show you how I'd do it logically.
note: access/pointer/reference are identical terms.
I'm going to value easy of development vs efficiency, sorry.
for each (non whitespace) line grab 2 elements. you can use regex-replace for ease of implementation. grab everything and replace the last 2 words with nothing, or if the rest of the experession does not terminate with a period replace it with '.', throw this into the following.
the last element of the original string goes into a linked list of the following structure: element, access to tasks, element.next. if an element does not exist append it to the list.
insert the first element of the original string into the head of the linked list of tasks, (task, task.next)
now you've input all your data. output time.
for each element in list of task titles print the task title, then
for each element in that task's access, output the task, newline, until element.next is nil. (don't forget your off by 1 error, make sure to print the final task before ending the loop).
You can also modify your task string at output instead of input, it's probably simpler.
do this until you're out of elements in your task list, then move to the next task title and repeat.
make sure you're outputting to a file type NOT the console.
IF this isn't homework, I'll do it though it'll be in Racket (PLT-Scheme, LISP) using tail recursion. LMK via PM if this is the case. Won't have time until tomorrow night though.
Have fun, hope this helps you.