E 是 a、b、c 和 d 的组合。 D 是最终结果。 所以 e 的结果应该与 d 相同。但事实并非如此。我做错了什么?
d = [24, 42, 30, 42, 48, 36] 的结果
e = [42, 42, 48, 36] 的结果
numbers = [2,4,7,2,5,3,7,8,1,6]
def mapping():
a = list(filter(lambda x : x > 3, numbers))
print(a)
b = list(map(lambda x : x * 3, a))
print(b)
c = list(filter(lambda x : x > 10, b))
print(c)
d = list(map(lambda x : x * 2, c))
print(d)
e = list(filter(lambda x : x > 3, map(lambda x : x * 3, filter(lambda x : x > 10, map(lambda x : x * 2, numbers)))))
print(e)
mapping()
请您参考如下方法:
问题在于,当您计算 e 时,您的操作顺序与计算 d 时的顺序相反。尝试像这样计算 e:
e = list(map(lambda x : x * 2,
filter(lambda x : x > 10,
map(lambda x : x * 3,
filter(lambda x : x > 3, numbers)))))
