Want to break the following code so that my functions are no larger than 10 statements
def start_end_indices(lines): """finds the beginning and ending lines""" start_index = lines.index('<begin step data>\n') end_index = lines.index('<end step data>\n', start_index + 1) return start_index, end_index def daily_totals_from_lines(lines, start_index, end_index): """iterates through all lines in list""" records = [] for line_num in range(start_index + 1, end_index): line = lines[line_num] date, step_string = line.strip().split(':') readings = step_string.split(',') total = 0 for reading in readings: steps = int(reading) total = total + steps line_data = (date, total) records.append(line_data) return records
def start_end_indices(lines): """finds the beginning and ending lines""" start_index = lines.index('<begin step data>\n') end_index = lines.index('<end step data>\n', start_index + 1) return start_index, end_index def get_total(readings): total = 0 for reading in readings: steps = int(reading) total = total + steps return total def get_readings(line): date, step_string = line.strip().split(':') readings = step_string.split(',') return (date, readings) def daily_totals_from_lines(lines, start_index, end_index): """iterates through all lines in list""" records = [] for line_num in range(start_index + 1, end_index): date, readings = get_readings(lines[line_num]) total = get_total(readings) line_data = (date, total) records.append(line_data) return records
Get Answers For Free
Most questions answered within 1 hours.