所以,这里有我正在为学校工作的这段代码
def sem1Sort(semester1, selectionSEM1):
for semester1["1"] in semester1:
if semester1["1"] in selectionSEM1:
print semester1["1"]
def main():
selectionSEM1 = ["a", "t", "b", "f", "d", "e"]
semester1 = {"1": ['a', 'e', 't', 'x', 'l', 'y'], "2": ['b', 'f', 'h', 'm', 'r', 'd'] ,
"3": ['a', 'b', 'j', 'k', 'o', 'q', 'u'], "4": ['c', 'l', 't', 'z', 'd', 'f'],
"5": [], "6": [], "7": [], "8": []}
main()
因此,在sem1Sort():方法中,它应获取semester1列表以及人工选择SEM1列表。之后,针对学期[“ 1”]列表中的每个不同索引,如果它位于selectionSEM1中,则应打印它,对吗?
我认为您的问题是“我如何获得在学生的选择和一个学期可用的课程中都可以找到的课程?”。在不更改数据格式化方式的情况下,请尝试使用此过滤方法。
def sem1Sort(semester1, selectionSEM1):
for period in semester1:
if period == '1':
for cls in semester1[period]:
if cls in selectionSEM1:
print cls
因为您只检查第一个期间
def sem1Sort(semester1, selectionSEM1):
print '\n'.join([cls for cls in semester1['1'] if cls in selectionSEM1])
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句