0
對於這個函數,出於某種原因,我得到錯誤,我無法弄清楚它有什麼問題。帶有氣泡排序功能的Python錯誤
def bubbleSort(lis):
for pas in lis:
for i in pas:
if lis[i] > lis[i+1]:
lis[i],lis[i+1] = lis[i+1],lis[i]
我收到以下錯誤:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
bubbleSort(hello)
File "C:/Users/albert/Desktop/test.py", line 4, in bubbleSort
for i in pas:
TypeError: 'int' object is not iterable
你是怎麼調用這個函數的?我的意思是你通過什麼作爲lis? – theharshest 2014-10-08 02:16:57