面试题答案
一键面试from functools import reduce
my_list = [1, 2, 3, 4, 5]
# 使用map函数将列表中的每个元素乘以2
result_map = list(map(lambda x: x * 2, my_list))
# 使用filter函数过滤出列表中的奇数
result_filter = list(filter(lambda x: x % 2 != 0, my_list))
# 使用reduce函数计算列表中所有元素的乘积
result_reduce = reduce(lambda x, y: x * y, my_list, 1)
print("map结果:", result_map)
print("filter结果:", result_filter)
print("reduce结果:", result_reduce)