Python - 类型错误:无法排序的类型:str() < int()

尼古拉斯·沃尔特斯

当我尝试运行我的代码时出现此错误。请帮忙,并解释它想说什么!

该程序旨在为每个候选人找到一个人的选票投票偏好(第一、第二、第三等),并删除他们的第一偏好。第一个偏好被替换为99999, 以方便我使用。

错误:

ERROR CODE: minIndex = int(vote.index(min(vote)))
TypeError: unorderable types: str() < int()

代码:

def countVotes(voteList):
candidatePreferences = []

for vote in voteList:
    minIndex = int(vote.index(min(vote)))
    candidatePreferences.append(minIndex)
    vote[minIndex] = 99999
return candidatePreferences

vList(第一次调用 countVotes 函数后):

[[99999, '3', '4', '5', '2'], ['4', '2', '5', '3', 99999], [99999, '3', '2', '5', '4'], [99999, '2', '4', '3', '5'], [99999, '3', '4', '5', '2'], ['2', 99999, '3', '5', '4'], [99999, '3', '4', '5', '2'], ['3', '5', '2', '4', 99999], [99999, '4', '5', '2', '3'], ['5', 99999, '4', '3', '2'], ['3', '2', '5', '4', 99999], ['3', 99999, '2', '5', '4'], ['2', '5', 99999, '4', '3'], ['3', '2', 99999, '4', '5'], ['4', '5', '3', 99999, '2'], [99999, '5', '4', '3', '2'], [99999, '5', '3', '4', '2'], ['2', 99999, '4', '3', '5'], ['4', 99999, '2', '5', '3']]

调用函数(第二次):

cp = countVotes(vList)

minIndex = int(vote.index(min(vote)))
TypeError: unorderable types: str() < int()
亚萨斯·古纳拉特尼

Python 不能将str值和int值一起排序在您的示例中99999是一个int值,而所有其他值都是str值。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

类型错误:无法排序的类型:int() > str()

类型错误:必须是 str,而不是 int;Python

PYTHON:根据包含 Intervals 的 dict 填充 df 的 nan 值 | 类型错误:无法排序的类型:Interval() < int()

Int + Str 类型的python

Python 2到3错误。TypeError:不可排序的类型:int()<= str()

Python:错误“类型错误:无法将 int 隐式转换为 str”

Python:类型错误:预期的 str、bytes 或 bytearray,而不是 int

保存Django表单会产生错误:无法排序的类型:int()> str()

不可排序的类型:str()<int()

不可排序的类型:str()> int()

类型错误:不支持 - 的操作数类型:'str' 和 'int' [Python]

类型错误:在冒泡排序中必须是 str,而不是 int

Python3-while ids> Stop:TypeError:不可排序的类型:str()> int()

类型错误:无法连接“str”和“int”对象 1

python-TypeError:无法排序的类型:str()> float()

python错误; +不支持的操作数类型:“ int”和“ str”

Python。类型错误:“str”和“int”的实例之间不支持“<”

Python类型错误:int对象不可迭代

类型错误:使用排序函数后“int”对象不可迭代(python 2.7)

类型错误:super() 参数 1 必须是类型,而不是 int (Python)

类型错误:“int”类型的对象在 python 中没有 len()

获取类型错误:int 类型的参数在 Python 中不可迭代

类型错误:无法将 str 连接到字节 - Python + pycryptodome

调用系列时,无法调用Python,Pandas和NLTK类型错误'int'对象

Python Web Scraping 错误类型错误:“int”对象不可迭代

rpsls游戏“(python)错误:无法连接'str'和'int'对象

python函数中的类型错误(int对象不可下标)

在Python中类型转换为'int'会产生错误的结果

Python:获取类型为int的参数不是可重复的错误