我有一個是由一定長度的子表,有點像[["a","b","c","d"],["a","b","c","d"],["a","b","c","d","e"]]
列表。我想要做的就是找到一種不具有一定的長度,然後打印出指數的子表的索引。例如,在示例清單,最後一個子表不具有四的長度,所以我會打印list 2 does not have correct length
。這是我到目前爲止:列印錯誤的子列表索引?
for i in newlist:
if len(i) == 4:
print("okay")
elif len(i) != 4:
ind = i[0:] #this isnt finished; this prints out the lists with the not correct length, but not their indecies
print("not okay",ind)
在此先感謝!
這確實有幫助!謝謝!只是想知道,有沒有辦法沒有對象,只有索引? – choochoopain
你需要有承擔其長度的對象,雖然。你可以在範圍使用'爲我(LEN(newlist)):'然後'newlist [I]',但是這被認爲unpythonic風格。 – DSM