您的位置:首页 > 编程语言 > Python开发

python核心编程-filter函数重构

2015-12-05 22:18 573 查看
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''filter第一次重构'''

from random import randint

allNums = []

for eachNum in range(9):
allNums.append(randint(1, 99))
print allNums
print filter(lambda n: n%2, allNums)


输出:

D:\Python27\test>func14.py
[36, 24, 36, 3, 98, 90, 82, 50, 63]
[3, 63]

D:\Python27\test>func14.py
[69, 68, 3, 91, 74, 43, 12, 43, 56]
[69, 3, 91, 43, 43]

D:\Python27\test>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: