portfolio = [
{'name': 'IBM', 'shares': 100, 'price': 91.1},
{'name': 'AAPL', 'shares': 50, 'price': 543.22},
{'name': 'FB', 'shares': 200, 'price': 21.09},
{'name': 'HPQ', 'shares': 35, 'price': 31.75},
{'name': 'YHOO', 'shares': 45, 'price': 16.35},
{'name': 'ACME', 'shares': 75, 'price': 115.65}
] 上面可以正常执行
print(list(filter(lambda portfolio:portfolio['shares']>100 ,portfolio))) 下面为什么不行
print(list(map(lambda portfolio:portfolio['shares'] if portfolio['shares']>100,portfolio)))
要写else
print(list(map(lambda portfolio:portfolio['shares'] if portfolio['shares']>60 else print(portfolio['shares']+1),portfolio)))
结果是,怎么去掉返回值None,map的好处是必须给了一个返回值,filter则只过滤需要的
51
36
46
[100, None, 200, None, None, 75]