# -*- coding: utf-8 -*- #python 27 #xiaodeng #Python之filter筛选数据工具 #http://python.jobbole.com/82597/ #1)filter语法格式: ''' filter(...) filter(function or None, sequence) -> list, tuple, or string '''
function:函数名
sequence:序列
#filter, 过滤 print list(filter((lambda x:x>0),range(-5,5)))#[1, 2, 3, 4] #等价于: #2)案例 k=range(-5,5) def func(x): if x>0: return x result=filter(func,k) print result,type(result)#[1, 2, 3, 4] <type 'list'>