I have a list like this
df = [‘20180001\tJane\t84\t73\n’, ‘20180002\tLee\t92\t89\n’, ‘20180007\tSteve\t57\t62\n’,
‘20180009\tDonald\t81\t84\n’, ‘20180011\tLuke\t58\t68\n’]
and I put it in to the dictionary with this code:
temp_dict = {}
for i in range(len(df)):
temp_dict[df[i].split(“\t”)[0]] = df[i].split(“\t”)[1:4]
for i in [*temp_dict]:
temp_dict[i][1] = int(temp_dict[i][1]) # (A)
temp_dict[i][2] = int(temp_dict[i][2].strip(“\n”)) # (B)
temp_dict[i].append((temp_dict[i][1] + temp_dict[i][2])/2) #average for A and B
temp_dict[i].append(grade((temp_dict[i][1] + temp_dict[i][2])/2)) #return average
#as letter grade
def grade(num):
if num>= 90:
return ‘A’
if num >= 80:
return ‘B’
if num >= 70:
return ‘C’
if num >= 60:
return ‘D’
else:
return ‘F’ #grade function
So temp_list comes like this:
{‘20180001’: [‘Jane’, 84, 73, 78.5, ‘C’],
‘20180002’: [‘Lee’, 100, 89, 90.5, ‘A’],
‘20180007’: [‘Steve’, 100, 62, 59.5, ‘F’],
‘20180009’: [‘Donald’, 81, 84, 82.5, ‘B’],
‘20180011’: [‘Luke’, 58, 68, 63.0, ‘D’]}
But everytime I update one of A or B, average and letter grade are not change. Is there anyway that average and letter grade automatically change when I update A or B?