python-small-examples

@author jackzhenguo
@desc 
@date 2019/4/6

65 压缩列表

def filter_false(lst):
    return list(filter(bool, lst))


r = filter_false([None, 0, False, '', [], 'ok', [1, 2]])
print(r)  # ['ok', [1, 2]]

[上一个例子](/python-small-examples/md/64.html) [下一个例子](/python-small-examples/md/66.html)