m從google教程學習python。我停留在與列表有關的練習上。 得到一個指數誤差python:IndexError:字符串索引超出範圍
lis[j]=words.pop()[i]
IndexError: string index out of range
我需要對列表進行排序,但是先從X的話應該是首當其衝。
代碼
def front_x(words):
i=0
lis=[]
j=0
k=0
words.sort()
while i<len(words):
if words[i][0:1]=="x":
lis[j]=words.pop()[i]
j+=1
i+=1
lis.extend(words)
while k<len(lis):
print(lis[k])
k+=1
return
您可以發佈您正在使用的數據嗎? – John