SCRIPT.PY
from roster import student_roster
from classroom_organizer import ClassroomOrganizer
import itertools
student_iter = iter(student_roster)
for i in range(10):
print(next(student_iter))
new_organizer = ClassroomOrganizer()
combos = new_organizer.student_combinations()
print(list(combos))
math_students = new_organizer.get_students_with_subject("Math")
science_students = new_organizer.get_students_with_subject("Science")
print(science_students)
math_and_science = itertools.combinations(math_students + science_students, 4)
print(list(math_and_science))
CLASSROOM_ORGANIZER.PY
from roster import student_roster
import itertools
# Import modules above this line
class ClassroomOrganizer:
def __init__(self):
self.sorted_names = self._sort_alphabetically(student_roster)
def _sort_alphabetically(self,students):
names = []
for student_info in students:
name = student_info['name']
names.append(name)
return sorted(names)
def __iter__(self):
self.index = 0
return self
def __next__(self):
if self.index >= len(self.sorted_names):
raise StopIteration
student_name = self.sorted_names[self.index]
self.index += 1
return student_name
def get_students_with_subject(self, subject):
selected_students = []
for student in student_roster:
if student['favorite_subject'] == subject:
selected_students.append((student['name'], subject))
return selected_students
def student_combinations(self):
seating_chart = itertools.combinations(self.sorted_names, 2)
return seating_chart
########
#organizer = ClassroomOrganizer()
#for name in organizer:
#print(name)