diff --git a/task-03/get_top_names.py b/task-03/get_top_names.py index 4535204..167a3b6 100644 --- a/task-03/get_top_names.py +++ b/task-03/get_top_names.py @@ -4,16 +4,25 @@ https://github.com/astropgh/learning-by-doing/tree/master/task-03 """ -def extract_data_lines(filename, start_text, end_text): +def extract_data_lines(filename, start_text, end_text, include_start, include_end): """ open `filename`, and yield the lines between the line that contains `start_text` and the line that contains `end_text` """ # fill in code as needed with open(filename) as fh: + on = False for line in fh: - # fill in code as needed - # use `yield line` to return desired lines but keep the function going + if start_text in line: + on = True + if not include_start: + continue + if end_text in line and not include_end: + break + if on: + yield line + if end_text in line and include_end: + break if __name__ == '__main__': @@ -21,5 +30,5 @@ def extract_data_lines(filename, start_text, end_text): start_text = '