字典生成式
1: 假设有20个学生,学生分数在60-100之间,筛选出成绩在90分以上的学生
方法一
import random
stuInfo={}
for i in range(20):
name = "westos"+ str(i)
score = random.randint(60,100)
stuInfo[name] = score
stuInfo["westos"+ str(i)] = random.randint(60,100)
print(stuInfo)
# 筛选出score>90
highScore = {}
for name, score in stuInfo.items():
if score > 90:
highScore[name] = score
print(highScore)
方法二 字典生成式
impo