Python: grade_school
This commit is contained in:
parent
b094d15ff7
commit
64012ef885
5 changed files with 170 additions and 0 deletions
22
python/grade-school/grade_school.py
Normal file
22
python/grade-school/grade_school.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import bisect
|
||||
from collections import defaultdict
|
||||
from typing import List, DefaultDict
|
||||
|
||||
|
||||
class School:
|
||||
def __init__(self) -> None:
|
||||
self.student_db: DefaultDict[int, List[str]] = defaultdict(list)
|
||||
|
||||
def add_student(self, name: str, grade: int) -> None:
|
||||
bisect.insort(self.student_db[grade], name)
|
||||
|
||||
def grade(self, grade_number: int) -> List[str]:
|
||||
|
||||
if grade_number not in self.student_db.keys():
|
||||
return []
|
||||
|
||||
return self.student_db[grade_number]
|
||||
|
||||
def roster(self) -> List[str]:
|
||||
return sum([self.grade(grade_number) for grade_number
|
||||
in sorted(self.student_db)], [])
|
||||
Loading…
Add table
Add a link
Reference in a new issue