以下功能出现错误。
我在运行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))