Pergunta de entrevista da empresa Apple

Python parsing a text file according to the requirements