EPIJudge
EPIJudge copied to clipboard
search_student fucntion on page 147 returns wrong result.
import collections
from typing import Tuple, List , Callable
import bisect
Student = collections.namedtuple("Student",('gpa','name'))
def comp_gpa(student : Student ) -> Tuple[float, str]:
return (-student.gpa, student.name)
def search_student(students : List[Student], target : Student,
comp_gpa : Callable[[Student], Tuple[float, str]]):
i = bisect.bisect_left([comp_gpa(s) for s in students], comp_gpa(target))
return 0 <= i < len(students) and students[i] == target
students = [Student(gpa,name) for gpa, name in zip([1,2,3,4],"abcd")]
print(search_student(students,Student(1, 'a'),comp_gpa))
it should print True but it prints False because, comp_gpa changes student_gpa to negative and that results in bisect_left returning the wrong index.
@gan3i what does search_student function is even supposed to do?
@mtorabirad search_student is supposed to check if the target(combination of gpa and name) is in the students list and return true incase it is present otherwise return false.