我是新來的蟒蛇,並試圖附加在列表的末端重複項內部消除改變順序追加複製在列表的最後項目內部消除改變順序
testlist = [1, 2, 32, 8, 1, 17, 5, 2, 42, 13, 56]
def duplicate(alist):
p = len(alist)
duplicate = False
for i in range(0, p):
for j in range (i + 1, p):
if alist[i] == alist[j]:
b = alist.index(alist[j])
a = alist.pop(b)
alist.append(a)
p -= 1
duplicate = True
print alist
if duplicate == False:
print "No duplicate item found"
duplicate(testlist)
OUTPUT:[32, 8, 1, 17, 5, 2, 42, 13, 56, 1, 2]
所需的輸出:[1, 2, 32, 8, 17, 5, 42, 13, 56, 1, 2]
任何幫助,我在這裏做什麼錯
你能解決您的代碼的縮進?我們不能告訴你是否有不正確的縮進問題:) – kfb
你認爲'alist.pop(b)'有什麼作用? –
您的代碼至少應該沒有語法錯誤(除非它是您需要幫助的語法)。此代碼目前不是語法Python – holdenweb