2013-11-22 41 views
-1

我一直收到錯誤無法訂購的類型:list()< int()。我做錯了什麼,我該如何解決?Python錯誤:無法訂購的類型:list()<int()

我的代碼:

import sys 
from List import * 


def main(): 

    strings=ArrayToList(sys.argv[1:]) 
    numbers=ListMap(int,strings) 

    smallest=numbers[0] 
    for i in range(len(numbers)): 
     if numbers[i]<smallest: 
      smallest=numbers[i] 
    return smallest 

    print("The smallest is", smallest(numbers)) 

main() 

錯誤:

Traceback (most recent call last): 
    File "command.py", line 18, in <module> 
    main() 
    File "command.py", line 12, in main 
    if numbers[i]<smallest: 
TypeError: unorderable types: list() < int() 
+0

回溯(最近通話最後一個): 文件 「command.py」 18行,在 的main() 文件 「command.py」,第12行,在主 如果[I] <最小: TypeError:無法訂購的類型:list() user3022573

+0

錯誤告訴你'numbers [0]'也是一個列表; ListMap()的定義是什麼? –

+1

你用'從列表導入*'導入的模塊是什麼? – YXD

回答

0

貌似你試圖比較整數的列表,這是不可能的Python3。確保numbers的所有項目都是整數。

>>> [] < 1 
Traceback (most recent call last): 
    File "<ipython-input-1-de4ae201066c>", line 1, in <module> 
    [] < 1 
TypeError: unorderable types: list() < int() 
+2

我認爲問題更多*爲什麼數字[0]是一個列表? –

相關問題