def get_programs_by_run(programs, enrollments):
 programs_by_run = {}
 course_ids = [unicode(e.course_id) for e in enrollments]
 for program in programs:
  for course_code in program['course_codes']:
   for run in course_code['run_modes']:
    run_id = run['course_key']
    if (run_id in course_ids):
     program_list = programs_by_run.setdefault(run_id, list())
     if (program not in program_list):
      program_list.append(program)
 for program_list in programs_by_run.itervalues():
  program_list.sort(key=(lambda p: p['name']))
 return (programs_by_run, course_ids)

def get_programs_by_run ( programs , enrollments ) : programs_by_run = { } course_ids = [ unicode ( e . course_id ) for e in enrollments ] for program in programs : for course_code in program [ 'course_codes' ] : for run in course_code [ 'run_modes' ] : run_id = run [ 'course_key' ] if ( run_id in course_ids ) : program_list = programs_by_run . setdefault ( run_id , list ( ) ) if ( program not in program_list ) : program_list . append ( program ) for program_list in programs_by_run . itervalues ( ) : program_list . sort ( key = ( lambda p : p [ 'name' ] ) ) return ( programs_by_run , course_ids )
intersect programs and enrollments .