from bisect import bisect
grades = "FEDCBA"
breakpoints = [30, 44, 66, 75, 85]
def grade(total):
return grades[bisect(breakpoints, total)]
print(grade(66))
print(list(map(grade, [33, 99, 77, 44, 12, 88])))
'''
C
['E', 'A', 'B', 'D', 'F', 'A']
[Program finished]'''
Not my program. Imported from enki.
Bisect module provides support for maintaining a list in sorted order without having to sort the list after each insertion.
So, when we call grade(66). It passes 66 to the grade function which returns C, How?
The second print statement is even more confusing.
It is mapping function grade with a List.
If I try to print, print (grades[bisect(breakpoints, grades)]),
I get Err,
TypeError: '<' not supported between instances of 'str' and 'int'