Parse python terminal output
Description:
Write a method that inputs a string which is the output of a python command line session, and returns the list of pairs (executed command, command printout).
In such an output, an issued command starts with >>>_
(where _
stands for space). If the command takes more lines, those lines start with ..._
, and the block ends with ...
, i.e., without space in the end of line.
A simple example of the input string is:
>>> print 42
42
>>> for x in 1,2,3:
... print x,
...
1 2 3
On this input, the method should return the following list.
[('print 42', '42'),
('for x in 1,2,3:\n print x,', '1 2 3')]
Also, take care of broken lines. First identify the length of the longest line, and if it is above the default 80 characters, take this as max_width
. Then, concatenate each line of length max_width
to the next line.
For example, the method on input
>>> 'x'*80
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x'
should return the command result without line break:
[("'x'*80", 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')]
However, on the input:
>>> print '01234567890123456789012345678901234567890123456789012345678901234567890123456789\nkeep linebreak'
01234567890123456789012345678901234567890123456789012345678901234567890123456789
keep linebreak
it should keep the linebreak after the 80 chars long line in the answer, because the longest line in the whole input string is longer.
Note: The empty commands should be ignored.
Similar Kata:
Stats:
Created | Feb 25, 2016 |
Published | Feb 28, 2016 |
Warriors Trained | 72 |
Total Skips | 0 |
Total Code Submissions | 277 |
Total Times Completed | 10 |
Python Completions | 10 |
Total Stars | 6 |
% of votes with a positive feedback rating | 80% of 5 |
Total "Very Satisfied" Votes | 4 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 5 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 5 kyu |