python學習:counter計數

一:定義一個list數組,求數組中每一個元素出現的次數java 若是用java來實現,是一個比較複雜的,須要遍歷數組list。python 可是python很簡單:看代碼數組 a = [1,4,2,3,2,3,4,2] from collections import Counter print Counter(a) 打印結果: Counter({2: 3, 3: 2, 4: 2, 1: 1}) s
相關文章
相關標籤/搜索