python - python TypeError:'list'和'int'的实例之间不支持'> ='
问题描述
我不断得到:TypeError: '>=' not supported between instances of 'list' and 'int'
在第 40 行代码如下,当我打印 while 语句中的值时,它们以整数形式返回:
pQueue = [['A', 4], ['B', 15], ['A', 15], ['A', 12]]
class priorityQueue():
def __init__(self,queue):
self.queue = queue
def sort(self):
length = len(self.queue)
tempListA = []
tempListB = []
tempListC = []
# splice the list depending if the letter is a b or c
for i in range(0, length):
tempItem = self.queue[i]
if tempItem[0] == 'A':
tempListA.append(tempItem)
elif tempItem[0] == 'B':
tempListB.append(tempItem)
elif tempItem[0] == 'C':
tempListC.append(tempItem)
#sort each list via number in positon
for i in range(0, len(tempListA)):
valueA = tempListA[i]
currentValueA = valueA[1]
positonA = i
a=tempListA[positonA-1]
b=a[1]
while (positonA>0) and (b>currentValueA):
tempListA[positonA]=tempListA[positonA-1]
positonA = [positonA-1]
tempListA[positonA]=valueA
print(tempListA)
#sort each list via number in positon
for i in range(0, len(tempListB)):
valueB = tempListB[i]
currentValueB = valueB[1]
positonB = i
a=tempListB[positonB-1]
b=a[1]
while (positonB>0) and (b>currentValueB):
tempListB[positonB]=tempListB[positonB-1]
positonB = [positonB-1]
tempListB[positonB]=valueB
print(tempListB)
#sort each list via number in positon for c
for i in range(0, len(tempListC)):
valueC = tempListC[i]
currentValueC = valueC[1]
positonC = i
a=tempListC[positonC-1]
b=a[1]
while (positonC>0) and (b>currentValueC):
tempListC[positonC]=tempListC[positonC-1]
positonC = [positonC-1]
tempListC[positonC]=valueC
print(tempListC)
# merge the lists back together
mergedQ = []
for i in range(0, len(tempListA)):
a = tempListA[i]
mergedQ.append(a)
print(mergedQ)
for i in range(0, len(tempListB)):
a = tempListB[i]
mergedQ.append(a)
print(mergedQ)
for i in range(0, len(tempListC)):
a = tempListC[i]
mergedQ.append(a)
print(mergedQ)
a = priorityQueue(pQueue)
a.sort()
上面代码的实际输出是:
[['A', 4], ['A', 15], ['A', 12]]
[['A', 4], ['A', 15], ['A', 12]]
Traceback (most recent call last):
File "66737040.py", line 108, in <module>
a.sort()
File "66737040.py", line 38, in sort
while (positonA>0) and (b>currentValueA):
TypeError: '>' not supported between instances of 'list' and 'int'
解决方案
推荐阅读
- mysql - SQL - on 语句后的内部连接语法
- python - 如何在忽略特定值的列表中检查重复值?
- java - OAuth2.0 的 Javax.xml.ws 客户端
- powershell - 将 3 个不同的对象组合成一个表
- go - 如何在 REST API 中管理映射模型
- java - Itext 7.0.2 图像顺时针旋转
- ms-access - 使用直通查询访问子表单
- python - 如何查询特定属性的熊猫数据框
- jboss-arquillian - 手动启动使用 ContainerBuilder 创建的 Arquillian Cube 容器
- spring - 使用数据表搜索不适用于弹簧数据