import random
list1 = [random.randint(-10,10) for _ in range(10)]
print('随机生成的十个在-10到10之间的整数列表:',list1)
outList1 = list(filter(lambda x: x>=0,list1))#filter返回一个可迭代对象
outList2 = [x for x in list1 if x >=0]#列表解析,快于filter
print('filter过滤列表中大于0的数:',outList1)
print('列表解析大于0的数:',outList2)
dict1 = {x: random.randint(60,100) for x in range(1,21)}
print('随机生成的20个值在60到100之间的整数的字典:',dict1)
kv = {k:v for k,v in dict1.items() if v>90}
print('字典中值大于90的:',kv)
set1 = set(list1)
print('列表转换成集合后:',set1)
outSet = {x for x in set1 if x%3==0}
print('集合内能被三整除的数:',outSet)
输出: