- # 求x以内的所有平方数:
- [x for x in xrange(1,100) if not x % math.sqrt(x)]
- # 求x以内(不包括x)的所有质数:
- filter(lambda x : not [x % i for i in xrange(2,int(math.sqrt(x)) + 1) if x % i == 0],xrange(2,x))
- # 求x的所有约数:
- [i for i in xrange(1,x + 1) if x % i ==0]
- #该片段来自于http://www.codesnippet.cn/detail/0104201512045.html
来源: http://www.codesnippet.cn/detail/0104201512045.html