Classrooms¶
Let’s consider the hypothetical scenario of a group of students who have taken a programming exam. The professor responsible of that exam is interested in knowing the pairs of students who got similar grades and were seating next to each other. The information available is the following:
- A grades dictionary: A
dictwhere:
the key is the Student Id (
int)the value is a
listwith the name (str) and the grade (float) of that student for that exam.For example:
>>> gradesD = { ... 107: ['JBB', 0.0], ... 227: ['JJJ', 6.5], ... 321: ['MMP', 5.5], ... 423: ['SCC', 7.5], ... 555: ['FCC', 5.0], ... 727: ['ABC', 0.0], ... 811: ['GMM', 8.0], ... 923: ['MRP', 10.0], ... }A class list: This is a 2-dimension list representing the locations where the students were seating during the exam. More precisely it is a
listof rows. Each row in turn is alistof Student Ids (int). For example:>>> cl51 = [ ... [227, 423, 811, 107], ... [923, 727, 321, 555], ... ]
Please implement the following Python function in the classrooms module (classrooms.py file):
- classrooms.gen_closeL(gradesD, classroomL, eps)¶
such that
given
gradesD, adictof grades as described above
classroomL, alistrepresenting a classroom as described above. It is garanteed that all Student Id in this list appear as keys ingradesD.
eps, afloatvalue that determines when two grades are similarreturns a
listwhere the elements are alsolistone for each row inclassroomL. Each sublist contains a tuple for each pair of students in that row seating next to each other whose grades difference is equal or less thaneps. This tuple has 4 components:
The name of the first student of the pair (the seating on the left side from our point of view).
The position in the row where he/she was seating.
The name of the student next to the first one (the seating on the right side from our point of view).
The absolute value of the difference of their grades.
Note
Seat positions are counted from left to right starting at 1.
For example, the function should behave as follows:
>>> gradesD = { ... 107: ['JBB', 0.0], ... 155: ['GWV', 5.5], ... 227: ['JJJ', 6.5], ... 275: ['AWV', 7.5], ... 321: ['MMP', 5.5], ... 325: ['BWV', 2.5], ... 423: ['SCC', 7.5], ... 490: ['BWV', 9.0], ... 555: ['FCC', 5.0], ... 727: ['ABC', 0.0], ... 811: ['GMM', 8.0], ... 923: ['MRP', 10.0], ... } >>> cl51 = [ ... [227, 423, 811, 107, 490], ... [155, 275, 325], ... [923, 727, 321, 555], ... ] >>> suspL = gen_closeL(gradesD, cl51, 1.0) >>> corrL = [ ... [('JJJ', 1, 'SCC', 1.0), ('SCC', 2, 'GMM', 0.5)], ... [], ... [('MMP', 3, 'FCC', 0.5)], ... ]
Notice that the second sublist in corrL is the empty list.
That’s because 155’s grade is not close to 275’s and in turn 275’s grade is not close to 325’s grade.
More doctests are available at the gen_closeL.test file.