Python3 实现集合条件过滤

版权声明:欢迎转载,总结并分享是进步的源泉和动力。 https://blog.csdn.net/GIS_BT/article/details/85030836
from random import randint

# 创建10个(-10,10)之间的随机数字列表

data = [randint(-10,10) for _ in range(10)]

# 创建集合
s = set(data)

#筛选集合中能被3整除的数字

{ x for x in s if x % 3 == 0}

猜你喜欢

转载自blog.csdn.net/GIS_BT/article/details/85030836
今日推荐