Created
October 18, 2018 16:47
-
-
Save hansrajdas/313e417bf2b06c9c7794f7ca5d9fc66e to your computer and use it in GitHub Desktop.
Problem description - https://drive.google.com/file/d/1TCiPO44wODkrh1i6WrFmbS4M1OeFIzbc/view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enter your code here. Read input from STDIN. Print output to STDOUT | |
BACKTRACE_START_STR = 'Traceback ' | |
BACKTRACE_END_STR = 'raise ' | |
BACKTRACE_SEPARATOR = '-' * 50 | |
def search_and_print_backtrace(logs): | |
line = 0 | |
is_backtrace = False | |
is_first_backtrace = True | |
while line < len(logs): | |
if BACKTRACE_START_STR in logs[line]: | |
is_backtrace = True | |
log_columns = logs[line].count(']') | |
if not is_first_backtrace: | |
print BACKTRACE_SEPARATOR | |
is_first_backtrace = False | |
if is_backtrace: | |
# Remove starting space and print only last column | |
print ']'.join(logs[line].split(']')[log_columns:])[1:] | |
if BACKTRACE_END_STR in logs[line]: | |
print ']'.join(logs[line + 1].split(']')[log_columns:])[1:] | |
is_backtrace = False | |
line += 1 | |
line += 1 | |
def main(): | |
raw_logs = [] | |
while True: | |
try: | |
raw_logs.append(raw_input()) | |
except: | |
break | |
search_and_print_backtrace(raw_logs) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment