filter与compress
作者:互联网
values = ['1', '2', '-3', '-', '4', 'N/A', '5']
def isNum(s):
try:
int(s)
return True
except:
return False
print(list(filter(lambda i: isNum(i), values)))
# 简写
print(list(filter(isNum, values))) # ['1', '2', '-3', '4', '5']
from itertools import compress
# 压缩?
print(list(compress(values, [isNum(i) for i in values]))) # ['1', '2', '-3', '4', '5']
标签:compress,list,isNum,filter,values,print 来源: https://www.cnblogs.com/fly-book/p/13396101.html