Here you are comparing semester1
with integer but semester1
is dict
object in sem1Sort2
function,
for period in semester1:
if semester1 == 2:
Actually you have to compare integer with key of dict
like this ,
for period in semester1:
if period == 2:
And your rest of will be like this ,
def sem1Sort1(semester1, selectionSEM1):
list = []
for period in semester1:
if period == 1:
for index in semester1[period]:
if index in selectionSEM1:
list.append(index)
return list
def sem1Sort2(semester1, selectionSEM1):
list = []
for period in semester1:
if period == 2:
for index in semester1[period]:
if index in selectionSEM1:
list.append(index)
return list
def main():
selectionSEM1 = ["a", "b", "c", "d", "e", "f", "g", "h"]
selectionSEM2 = []
semester1 = {
1: ["e", "f", "g", "h"], 2: ["a", "b", "c", "d"] ,
}
SEM1period1 = sem1Sort1(semester1, selectionSEM1)
SEM1period2 = sem1Sort2(semester1, selectionSEM1)
print SEM1period1
print SEM1period2
main()
Output:
['e', 'f', 'g', 'h']
['a', 'b', 'c', 'd']