【Python】filter()的结果仍可以被filter()

2023-06-20,,


def test_twice_filter():
    list_a = [1, 2, 3, 4, 5]
    x = filter(lambda m: m > 2, list_a)
    y = filter(lambda n: n < 4, x)
    print(list(y))

if __name__ == '__main__':
    test_twice_filter()

结果:

ssh://root@250.250.250.250:250/usr/bin/python3.6 -u /home/dba/HAL_9000/dbAlertAPP/filters/misc_item_filter.py
[3]

参考阅读:

  • Listing a filter object twice will return a blank list?