看板 Python 關於我們 聯絡資訊
※ 引述《plom (plom)》之銘言: : 大家好, 請教各位: : a=['abc','cdrf','abc','erd','abc'] : 則 a.index = 0 : 是否可有辦法一次找出所有"abc" 的 index 位置? : 例 a.index = [0,2,4] 看一下內建函數好像沒有這個功能 自己寫一個獻醜一下 def indexs(data,sub): i=0 result=[] try: while 1: i=data.index(sub,i) result.append(i) i+=1 except ValueError,e: pass return result a=['a','b','a'] print indexs(a,'a') -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.116.141.78