>>> test1 = ["aaa","bbb","aaa","aaa","ccc","ccc","ddd","aaa","ddd","eee","ddd"] >>> test1.count("aaa") ## 統計指定元素出現的次數 4
>>> test1.count("bbb") 1
>>> test2 = [] >>> for i in test1: ## 去重復 if i not in test2: test2.append(i) >>> test2 ['aaa', 'bbb', 'ccc', 'ddd', 'eee'] >>> for i in test2: ## 統計每一個元素出現的次數 print(f"{i}:{test1.count(i)}") aaa:4 bbb:1 ccc:2 ddd:3 eee:1
>>>