# filter()函数是python内置的另一个有用的高阶函数
# filter()函数接收一个函数f和一个list,
# 这个函数f的作用是对每个元素进行判断,返回True或False
# filter()根据判断结果自动过滤掉不符合条件的元素
# 返回由符合条件元素组成的新list
a = [1, 2, 3, 4, 5, 6]
b = filter(lambda x: x % 2 == 1, a)
print(b) # <filter object at 0x00000238F3279128>
for item in b:
print(item) # 1 3 5
print([item for item in filter(lambda x: x % 2 == 1, a)]) # [1, 3, 5]
# 使用列表解析来实现
print([item for item in a if item % 2 == 1]) # [1, 3, 5]