#需求1:假設有20個學生,學生的分數在60~100之間,篩選出成績在90分以上的學生python
import randomdom
stuInfo = {}
for i in range(20):
name = 'westos' + str(i)
score = random.randint(60, 100)
stuInfo[name] = score
print(stuInfo)ide
highscore = {}
for name,score in stuInfo.items():
if score > 90:
highscore[name] = score
print(highscore)
print({name: score for name, score
in stuInfo.items() if score > 90})blog
#需求2:將全部的key值都變成大寫 get
#需求3:大小寫的key值合併,統一以小寫輸出it
d = dict(a=1, b=2, c=3, B=9, A=10)
a=11 b=11 c=2
new_d = {}class
for k,v in d.items():
low_k = k.lower()
if low_k not in new_d:
new_d[low_k] = v
else:
new_d[low_k] += vimport
print(new_d)im
print({k.lower():d.get(k.upper(),0)+d.get(k.lower(),0)
for k in d})db