>>> 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
>>> 

 

相关文章:

  • 2021-11-29
  • 2022-02-17
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2021-05-22
相关资源
相似解决方案