1 Star 0 Fork 0

前端代码工具库 / python_demo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
filter.py 856 Bytes
一键复制 编辑 原始数据 按行查看 历史
diogoxiang 提交于 2015-11-30 21:27 . 一些测试的东西
# coding=utf-8
# 过滤反转
# 回数
def is_palindrome(n):
return str(n) == str(n)[::-1]
output = filter(is_palindrome, range(1, 1000))
#print(list(output))
# 计算
def is_odd(n):
return 1 == n % 2
L = range(100)
#print(list(filter(is_odd, L)))
def not_empty(s):
return s and s.strip()
#print(list(filter(not_empty, ['A', '', 'B', None, 'C', ' '])))
def main():
for n in primes():
if n < 1000:
print(n)
else:
break
def _odd_iter():
n = 1
while True:
n = n + 2
yield n
def _not_divisible(n):
return lambda x: x % n > 0
def primes():
yield 2
it = _odd_iter()
while True:
n = next(it)
yield n
it = filter(_not_divisible(n), it)
if __name__ == '__main__':
main()
Python
1
https://gitee.com/tomxiang/python_demo.git
git@gitee.com:tomxiang/python_demo.git
tomxiang
python_demo
python_demo
master

搜索帮助