What are Python's equivalent of Javascript's reduce(), map(), and filter()?

前端 未结 3 694
轮回少年
轮回少年 2021-01-31 10:27

What are Python\'s equivalent of the following (Javascript):

function wordParts (currentPart, lastPart) {
    return currentPart+lastPart;
}

word = [\'Che\', \'         


        
3条回答
  •  执笔经年
    2021-01-31 11:06

    The first is:

    from functools import *
    def wordParts (currentPart, lastPart):
        return currentPart+lastPart;
    
    
    word = ['Che', 'mis', 'try']
    print(reduce(wordParts, word))
    

提交回复
热议问题