Python filter创建迭代器(1ni)

# *_*coding:utf-8 *_*

values = ['1', '2', '-3', '-', '4', 'N/A', '5']

def is_int(val):
    try:
        x = int(val)
        return True
    except Exception:
        return False


ivals = list(filter(is_int, values))
print(ivals)
# Outputs ['1', '2', '-3', '4', '5']

is_int 是判断函数

猜你喜欢

转载自blog.csdn.net/qq_40952927/article/details/80810851