将一个包含MisCourseIdSwitch对象的列表list转换为一个Map其中key是MisCourseIdSwitch对象的sysCourseId属性加schoolID属性value是对应的MisCourseIdSwitch对象
可以使用字典推导式来实现这个转换过程。假设给定的列表为mis_course_list,可以按如下方式将其转换为一个字典:
mis_course_dict = {course.sysCourseId + course.schoolID: course for course in mis_course_list}
这里使用了字典推导式的语法,遍历mis_course_list中的每个MisCourseIdSwitch对象,并以course.sysCourseId + course.schoolID作为key,course作为value,最终得到一个字典mis_course_dict。
原文地址: http://www.cveoy.top/t/topic/ii7o 著作权归作者所有。请勿转载和采集!