I am using an open source Python code. I think it has been written for Python 2, when I run it in Python3.3 I get this error:
TypeError: must use keyword argument for key function
pointing to these lines of code:
probs = [(word, pool[word]) for word in words if word in pool]
probs.sort(lambda x,y: cmp(y[1],x[1]))
Also similar part of the code:
for pname, pprobs in pools.items():
p = self.getProbs(pprobs, tokens)
if len(p) != 0:
res[pname] = self.combiner(p, pname)
res = res.items()
res.sort(lambda x,y: cmp(y[1], x[1]))
gives the same error.
I am a beginner in Python, so I appreciate if somebody can tell me how should I change the code.
cmp
has been depracated. Usekey
instead.