This is sort of an assignment or 'homework' problem as you people say and I clarify it in the beginning only. I am new to Python and I really get confused with this kind of problems.
The problem stated is : Care hospital wants to know the medical speciality visited by the maximum number of patients. Assume that the patient id of the patient along with the medical speciality visited by the patient is stored in a list. The details of the medical specialities are stored in a dictionary as follows: { "P":"Pediatrics", "O":"Orthopedics", "E":"ENT }
Write a function to find the medical speciality visited by the maximum number of patients and return the name of the speciality.
Code I attempted:
def max_visited_speciality(patient_medical_speciality_list,medical_speciality):
speciality_list=[]
for words in patient_medical_speciality_list:
if words in medical_speciality:
speciality_list.append(words)
speciality=max(speciality_list)
return speciality
#provide different values in the list and test your program
patient_medical_speciality_list=[301,'P',302, 'P' ,305, 'P' ,401, 'E' ,656, 'E']
medical_speciality={"P":"Pediatrics","O":"Orthopedics","E":"ENT"}
speciality = max_visited_speciality(patient_medical_speciality_list,medical_speciality)
print(speciality)
Sample Input : [101,P,102,O,302,P,305,P]
Expected Output : Pediatrics
Output I am getting : P