Привет, я пытаюсь добавить два значения в словарь, см. Код ниже, но я хочу добавить средний балл к их именам.Проблемы с языком Python
Question = raw_input("""How would you like to view the class?
A) By Average, highest to lowest:
B) By Highest score, highest to lowest:
C) By Alphaetical order:
""")
Question = Question.title()
if Question == "A" :
for key, value in Classdict.items():
Avg = sum(map(int, value))/ float(len(value))
global AvgDict
AvgDict = {}
for key in Classdict:
if key in AvgDict:
AvgDict[key].append(Avg)
else:
AvgDict[key] = Avg
print AvgDict
Classopen.close()
Questiontwo = raw_input("""How would yuu like to view it?
A)By highest score, highest to lowest:
B)By Alphaetical order:
""")
Questiontwo = Questiontwo.title()
if Questiontwo == "A":
print "You selected highest score, highest to lowest"
sortedavghigh = sorted(AvgDict.items(), key=operator.itemgetter(1))
print sortedavghigh[::-1]
elif Questiontwo == "B":
print "You selected to sort it alphabetically"
sortedavgapha = sorted(AvgDict.items(), key=operator.itemgetter(0))
print sortedavgalpha
Какую информацию вы пытаетесь сохранить/вы сохранили в вашем 'Classdict'? –