[英]"TypeError: '>' not supported between instances of 'int' and 'NoneType'"
[英]TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'
我正在嘗試對python中的整數列表進行排序這是我的代碼
for i in range (5):
for j in range (6):
list_dist.append(dist(i,j,pos_porte))
sorted_list=sorted (list_dist)
由於某種原因,它無法正常工作,您能幫忙嗎?
編輯:dist是一個返回距離的函數:
def dist(a,s,b):
distance=sqrt((pow(a-b[0],2)+pow(s-b[1],2)))
print(distance)
無論dist
函數正在做什么,它都不會返回任何內容。 因此list_dist
包含None
並且這些不能排序。
您在dist
函數中缺少return
語句。 您可以像這樣更新它:
def dist(a,s,b):
return sqrt((pow(a-b[0],2)+pow(s-b[1],2)))
請注意, print
只不過是打印您輸入到stdout的任何內容而已,它並不會改變您的函數缺少return
語句的事實,因此始終返回None
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.