123456789101112131415161718 |
- # filter Принимает True или False
- def f(x):
- return x > 10
- def test_filter():
- a = [1, 0, 23, 0, 34, 2, 7, 3, 45]
- l_1 = list(filter(f, a))
- l_2 = list(filter(bool, a))
- print(l_1)
- print(l_2)
- def f_1():
- numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- print(list(filter(lambda x: not x%2, numbers)))
- f_1()
|