#The diary of a Python learner
Date:22.12.2023 Fri.
Focus:lambda匿名函数
Key:
lambda不需要返回值
可以直接在return里用
Practice:
1.请用匿名函数改造下面的代码:
# -*- coding: utf-8 -*-
# def is_odd(n):
# return n % 2 == 1
#
# L = list(filter(is_odd, range(1, 20)))
L = list(filter(lambda x:x%2==1, range(1, 20)))
print(L)
2.
# -*- coding: utf-8 -*-
import
Difficulty?
Too easy
Addition:
复习了一下filter函数可以进行对输入的T/F进行判断并筛选