在Python排序列表时类型错误时,我试图返回:试图从一个文件
- 唯一字
- 发生次数的文件中的计数排序列表
我不断收到错误:
TypeError: '<' not supported between instances of 'int' and 'str'.
我的代码如下:
def countWords(ifile):
lst1=[]
infile=open(ifile,'r')
lines=(inifle.read()).lower()
for element in lines.split():
lines.replace(',',' ')
sct=lines.count(element)
lst1.append(element)
lst1.append(sct)
return lst1.sort()
infile.close()
我在做什么错?
错误告诉你什么是错的:你试图理清同时包含字符串和数字的列表。什么应该考虑更大'9'或''狗'? – Julien
'狗'将被视为更大 –
如果您的问题得到解答,您可以[接受最有帮助的](https://stackoverflow.com/help/someone-answers)。 –