更好的代码列表中的grepping元素代码

时间:2017-05-30 07:35:26

标签: python

我正在寻找这部分代码的不错选择:

    def reportResult (finalParsResult):

        print "Total Number of Mimatch Files:", 
        diffSum=0
        for (gP, matchFiles, diffFiles, matchFolders, gpExtrFld, upExtraFldrs) in FinalResult:
            diffSum=diffSum+len(diffFiles)
        print "Number of diff files", diffSum

有什么建议吗?

1 个答案:

答案 0 :(得分:1)

def reportResult(finalParsResult):
    return sum(len(result_row[2]) for result_row in FinalResult)

或者,如果FinalResult实际上应该是参数finalParsResult

def reportResult(finalParsResult):
    return sum(len(result_row[2]) for result_row in finalParsResult)