在列表、字典、集合中根据条件筛选数据
from random import randint data=[randint(-10,10) for i in range(10)] print(data) a=[x for x in data if x>=0]#列表解析 print(a) stu={x:randint(60,100) for x in range(1,21)}#字典解析 print(stu) stu1={k:v for k,v in stu.items() if v>90} print(stu1) s=set(data) print(s) s1={x for x in s if x %3==0} #集合解析 print(s1)