按支持,置信度对项目集进行排序的调用函数时出错

时间:2018-09-18 13:49:14

标签: python python-3.x

以下功能出现错误。

我在运行for循环的语法时遇到错误,该循环遍历一组项目并按支持对它们进行排序。

for item, support in sorted(item, key=lambda (item, support): support):
                                             ^
SyntaxError: invalid syntax

def printResults(items, rules):
"""prints the generated itemsets sorted by support and the confidence rules sorted by confidence"""
    for item, support in sorted(items, key=lambda (item, support): support):
    print "item: %s , %.3f" % (str(item), support)
    print("\n------------------------ RULES:")
    for rule, confidence in sorted(rules, key=lambda (rule, confidence): confidence):
       pre, post = rule
       print("Rule: %s ==> %s , %.3f" % (str(pre), str(post), confidence))

0 个答案:

没有答案