Is there a map without result in python?

前端 未结 15 1135
北恋
北恋 2020-12-03 04:33

Sometimes, I just want to execute a function for a list of entries -- eg.:

for x in wowList:
   installWow(x, \'installed by me\')

Sometime

15条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 05:17

    If you're worried about the need to control the return value (which you need to do to use filter) and prefer a simpler solution than the reduce example above, then consider using reduce directly. Your function will need to take an additional first parameter, but you can ignore it, or use a lambda to discard it:

    reduce(lambda _x: installWow(_x, 'installed by me'), wowList, None)
    

提交回复
热议问题