這裏的故事讓每個項目的索引,次數我有兩個列表:如何使用itertools.groupby()
list_one=[1,2,9,9,9,3,4,9,9,9,9,2]
list_two=["A","B","C","D","A","E","F","G","H","Word1","Word2"]
我想找到list_one連續9的的indicies這樣我可以得到從list_two對應的字符串,我已經試過:
group_list_one= [(k, sum(1 for i in g),pdn.index(k)) for k,g in groupby(list_one)]
我希望得到前9的索引中的每個元組,然後嘗試從那裏走,但沒有工作..
我能做什麼h ERE? PS:我已經看了itertools的文檔,但它似乎很模糊,我.. 預先感謝
編輯: 預期輸出(鍵,occurances,index_of_first_occurance) 像
[(9, 3, 2), (9, 4, 7)]
什麼是您預期的輸出? – bozdoz