从集合中提取数据也是有两种方法:过滤,列表解析式:
#!/usr/bin/env python #coding:utf-8 #@Author:Andy from random import randint data = [randint(1, 11) for x in range(1, 11)] print(data) #Translate to set set1 = set(data) # filter the n which can % 3 res1 = {x for x in set1 if x %3 ==0 } res2 = filter(lambda x : x %3 == 0 , set1) print(res1) print(list(res2))