我得到了这样的输出:
白细胞
中性粒细胞
淋巴细胞
单核细胞
结果
8.25 K/L
4.29 K/μL
3.55 K/L
0.25
但是,我想逐行输出,比如:
白细胞8.25K/L
中性粒细胞4.29K/μL
淋巴细胞3.55K/L
发布于 2022-09-19 04:21:56
您应该解析输出,将标签和结果分离成两个单独的列表,然后将它们合并在一起。
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)输出:
White Blood Cells 8.25 K/µL
Neutrophil 4.29 K/μL
Lymphocyte 3.55 K/µL
Monocyte 0.25https://stackoverflow.com/questions/73768099
复制相似问题