TypeError; Must use key word argument or key function in python 3.x -
i new python, trying port script in 2.x 3.x encountering error typeerror; must use key word argument or key function in python 3.x. below piece of code: please help
def resort_working_array( self, chosen_values_arr, num ): item in self.__working_arr[num]: data_node = self.__pairs.get_node_info( item ) new_combs = [] in range(0, self.__n): # numbers of new combinations created if item appended array new_combs.append( set([pairs_storage.key(z) z in xuniquecombinations( chosen_values_arr+[item], i+1)]) - self.__pairs.get_combs()[i] ) # weighting node item.weights = [ -len(new_combs[-1]) ] # node creates of new pairs best item.weights += [ len(data_node.out) ] # less used outbound connections produce more new pairs while search continues item.weights += [ len(x) x in reversed(new_combs[:-1])] item.weights += [ -data_node.counter ] # less used node better item.weights += [ -len(data_node.in_) ] # otherwise prefer node of free inbound connections; somehow works out better ;) self.__working_arr[num].sort( key = lambda a,b: cmp(a.weights, b.weights) )
looks problem in line.
self.__working_arr[num].sort( key = lambda a,b: cmp(a.weights, b.weights) )
the key
callable should take 1 argument. try:
self.__working_arr[num].sort(key = lambda a: a.weights)
Comments
Post a Comment