gpt4 book ai didi

python-3.x - 类型错误;必须在 python 3.x 中使用关键字参数或键函数

转载 作者:行者123 更新时间:2023-12-04 02:55:16 24 4
gpt4 key购买 nike

我是 python 新手,试图将 2.x 中的脚本移植到 3.x 我遇到错误 TypeError;必须在 python 3.x 中使用关键字参数或键函数。下面是一段代码:请帮忙

def resort_working_array( self, chosen_values_arr, num ):
for item in self.__working_arr[num]:
data_node = self.__pairs.get_node_info( item )

new_combs = []
for i in range(0, self.__n):
# numbers of new combinations to be created if this item is appended to array
new_combs.append( set([pairs_storage.key(z) for z in xuniqueCombinations( chosen_values_arr+[item], i+1)]) - self.__pairs.get_combs()[i] )
# weighting the node
item.weights = [ -len(new_combs[-1]) ] # node that creates most of new pairs is the best
item.weights += [ len(data_node.out) ] # less used outbound connections most likely to produce more new pairs while search continues
item.weights += [ len(x) for x in reversed(new_combs[:-1])]
item.weights += [ -data_node.counter ] # less used node is better
item.weights += [ -len(data_node.in_) ] # otherwise we will prefer node with most of free inbound connections; somehow it works out better ;)

self.__working_arr[num].sort( key = lambda a,b: cmp(a.weights, b.weights) )

最佳答案

看起来问题出在这一行。

self.__working_arr[num].sort( key = lambda a,b: cmp(a.weights, b.weights) )
key callable 应该只接受一个参数。尝试:
self.__working_arr[num].sort(key = lambda a: a.weights)

关于python-3.x - 类型错误;必须在 python 3.x 中使用关键字参数或键函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29943146/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com