Is there a map without result in python?

前端 未结 15 1126
北恋
北恋 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:16

    if it is ok to distruct wowList

    while wowList: installWow(wowList.pop(), 'installed by me')
    

    if you do want to maintain wowList

    wowListR = wowList[:]
    while wowListR: installWow(wowListR.pop(), 'installed by me')
    

    and if order matters

    wowListR = wowList[:]; wowListR.reverse()
    while wowListR: installWow(wowListR.pop(), 'installed by me')
    

    Though as the solution of the puzzle I like the first :)

提交回复
热议问题