我想按class1
的值排序score_list
。Python:我如何排序字典裏面的列表
我可以按字母順序對score_list
進行排序,只需對鍵進行排序,但我無法弄清楚如何從最大到最小的數值排序列表。
此外,我想score_list
只存儲最後3個輸入,如果可能,我想找到每個學生最後3個分數的平均值。
enter code here:
score_list = []
class1 = {}
what_class = input ("what class would you like?")
if what_class == ("1") :
print("class1 results")
student_name =input("name?")
score = input("score?")
choose = input("do you want to entre another student? y,n")
while choose == "y":
student_name =input("name?")
score = input("score?")
score_list.append(score)
choose = input("do you want to entre another score? y,n")
class1.setdefault(student_name,score_list)
if choose == "n":
sorted_names = sorted(class1.keys())
print(class1)
class1_items = class1.items()
print (type(class1_items))
for i in class1_items:
print (i)
,如果有人能幫助我,我會非常感激它
感謝你的幫助
[]的目標更好看:1
enter code here
import heapq
from collections import deque
print("alphabetical(type:A),highest to lowest(type:B),Average(type:C)")
student_name = input("ENTER NAME")
result_type = input ("WHICH TYPE OF RESULTS WOULD YOU LIKE?")
which_class = input ("which class?")
if result_type == ("A") or result_type == ("a"):
print("alphabetical order(type:A)")
if result_type == ("B") or result_type == ("b"):
print("results in highest to lowest.")
score_list = deque(maxlen=3)
scores = input("Please enter your score.")
choose = input("do you want to entre another score? y,n")
while choose != "n":
scores = input("Please enter your score.")
choose = input("do you want to entre another score? y,n")
score_list.append(scores)
if choose != "y" :
print(score_list)
print((student_name)+"'s:"+"lowest to largest"+str(heapq.nsmallest(3, score_list)))
print((student_name)+"'s:"+"largest to lowest"+str(heapq.nlargest(3, score_list)))
if result_type == ("C") or result_type == ("c"):
print("results in average order.")
score_list = deque(maxlen=3)
scores = input("Please enter your score.")
choose = input("do you want to entre another score? y,n")
while choose != "n":
scores = input("Please enter the scores.")
choose = input("do you want to entre another score? y,n")
score_list.append(int(scores))
#print(len(score_list))
#print(sum(score_list))
total = (int(sum(score_list)))
length = (int(len(score_list)))
average= (total)/(length)
if choose != "y" :
print(student_name+"'s "+"average score:"+str(average))
#print("average: " +str(average))
這是怎麼了我改進了它,我仍然無法弄清楚按字母順序排序的部分。
the objectives to help you know what i am trying to do
,這並不似乎工作:這是我的任務 •\t做一個日誌,根據他們的表現給用戶。 •\t系統應該存儲每個學生的最後三個分數。 •\t輸出的測驗結果的特定類,分類: •\t與每個學生得分最高的測試 •\t由最高得分按字母順序排列,從最高到最低 •\t通過平均分,最高以最低 •\t允許教師在排序輸出數據時選擇要查看哪個課程組以及使用哪個字段。 –
他沒有爲每個學生存儲多個測試分數,從我可以收集的數據中。編輯:好吧,所以我想他正在評論他的評論對不起! – Chris
哦,男人,你只是太懶惰,python足夠方便表達想法 –