Re: [問題] 關於 index 用法

看板Python作者 (殘雲奪月)時間17年前 (2008/07/07 16:05), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《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
文章代碼(AID): #18SSvBtD (Python)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
文章代碼(AID): #18SSvBtD (Python)