Skip to content

Commit 738a202

Browse files
authored
Create Assignment on Dictionary - Level 3.py
1 parent f64aa1b commit 738a202

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'''
2+
Problem Statement
3+
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:
4+
{
5+
"P":"Pediatrics",
6+
"O":"Orthopedics",
7+
"E":"ENT
8+
}
9+
10+
Write a function to find the medical speciality visited by the maximum number of patients and return the name of the speciality.
11+
12+
Note:
13+
14+
Assume that there is always only one medical speciality which is visited by maximum number of patients.
15+
16+
Perform case sensitive string comparison wherever necessary.
17+
18+
Sample Input
19+
20+
[101,P,102,O,302,P,305,P]
21+
[101,O,102,O,302,P,305,E,401,O,656,O]
22+
[101,O,102,E,302,P,305,P,401,E,656,O,987,E]
23+
24+
Expected Output
25+
26+
Pediatrics
27+
Orthopedics
28+
ENT
29+
'''
30+
31+
#lex_auth_012693816757551104165
32+
33+
def max_visited_speciality(patient_medical_speciality_list,medical_speciality):
34+
# write your logic here
35+
p=o=e=0
36+
for i in range(1,len(patient_medical_speciality_list),2):
37+
if patient_medical_speciality_list[i]=='P':
38+
p=p+1
39+
elif patient_medical_speciality_list[i]=='O':
40+
o=o+1
41+
elif patient_medical_speciality_list[i]=='E':
42+
e=e+1
43+
if p>e and p>o:
44+
max=p
45+
elif e>p and e>o:
46+
max=e
47+
else:
48+
max=o
49+
if max==p:
50+
speciality="Pediatrics"
51+
elif max==e:
52+
speciality="ENT"
53+
else:
54+
speciality="Orthopedics"
55+
56+
return speciality
57+
58+
#provide different values in the list and test your program
59+
patient_medical_speciality_list=[301,'P',302, 'P' ,305, 'P' ,401, 'E' ,656, 'E']
60+
medical_speciality={"P":"Pediatrics","O":"Orthopedics","E":"ENT"}
61+
speciality=max_visited_speciality(patient_medical_speciality_list,medical_speciality)
62+
print(speciality)
63+
64+
patient_medical_speciality_list=[101, 'O', 102, 'O', 302, 'P', 305, 'E', 401, 'O', 656, 'P']
65+
medical_speciality={'O': 'Orthopedics', 'E': 'ENT', 'P': 'Pediatrics'}
66+
speciality=max_visited_speciality(patient_medical_speciality_list,medical_speciality)
67+
print(speciality)

0 commit comments

Comments
 (0)