contoh program Python yang memisahkan dan mengkategorikan hasil patologi dari daftar string:

Jan 13 2023
.

pathology_results = [
    "Abnormal: High white blood cell count",
    "Normal: Negative for cancer",
    "Abnormal: Elevated liver enzymes",
    "Normal: No abnormalities detected",
    "Abnormal: High blood sugar",
    "Abnormal: High cholesterol"
]

abnormal_results = {}
normal_results = []

for result in pathology_results:
    if "Abnormal" in result:
        # Extract the condition from the result string
        condition = result.split(':')[1].strip()
        
        # Check if the condition is already in the abnormal results dictionary
        if condition in abnormal_results:
            abnormal_results[condition] += 1
        else:
            abnormal_results[condition] = 1
    elif "Normal" in result:
        normal_results.append(result)

print("Abnormal Results:")
for condition, count in abnormal_results.items():
    print(f"{condition}: {count}")

print("\nNormal Results:", normal_results)