I get outputs like this:
White Blood Cells
Neutrophil
Lymphocyte
Monocyte
Result
8.25 K/µL
4.29 K/μL
3.55 K/µL
0.25
But instead, I want to output line by line, like:
White Blood Cells 8.25 K/µL
Neutrophil 4.29 K/μL
Lymphocyte 3.55 K/µL
I get outputs like this:
White Blood Cells
Neutrophil
Lymphocyte
Monocyte
Result
8.25 K/µL
4.29 K/μL
3.55 K/µL
0.25
But instead, I want to output line by line, like:
White Blood Cells 8.25 K/µL
Neutrophil 4.29 K/μL
Lymphocyte 3.55 K/µL
You should parse the output, separating the labels and results into two separate lists, and then merge them together.
input_str = """White Blood Cells
Neutrophil
Lymphocyte
Monocyte
Result
8.25 K/µL
4.29 K/μL
3.55 K/µL
0.25"""
input_split = input_str.split('\n')
label_list = []
result_list = []
read_result = False
for line in input_split:
if line == "Result":
read_result = True
continue
if read_result:
result_list.append(line)
else:
label_list.append(line)
for (result, label) in zip(label_list, result_list):
print(result, label)
Output:
White Blood Cells 8.25 K/µL
Neutrophil 4.29 K/μL
Lymphocyte 3.55 K/µL
Monocyte 0.25