返回: Python基础 索引页
下面的代码,是之前所写的 【Python基础】以条件数组、匹配检查另一个数组的例子
的改进版。通过函数实现匹配检查。
def makeSearch(tmpActionList, tmpKeywordList): tmpCnt = 0 tmpVals = tmpActionList[1] for j in range (len(tmpVals)): curVal = tmpVals[j] ## for i in range(len(tmpKeywordList)): ##print (curVal) ##print ( tmpKeywordList[i] ) if (curVal == tmpKeywordList[i]): tmpCnt = tmpCnt +1 ## ## ## tmpActionList[0][1] = tmpCnt ##print(actionList) ## actionList = [] tmpFactor= [] tmpFactor.append("[Action --1]") tmpFactor.append(0) contents = [] contents.append("condition aa") contents.append("condition kk") contents.append("condition rr") contents.append("condition cc") actionList.append(tmpFactor) actionList.append(contents) keywordList = [] keywordList.append("condition aa") keywordList.append("condition kk") keywordList.append("condition cc") makeSearch(actionList, keywordList) print (actionList)
输出结果如下:
[['[Action --1]', 3], ['condition aa', 'condition kk', 'condition rr', 'condition cc']]
返回: Python基础 索引页