Python找出列表中出现次数最多的元素

greatefanli 27 0 PDF 2020-12-23 02:12:28

方式一: 原理:创建一个新的空字典,用循环的方式来获取列表中的每一个元素,判断获取的元素是否存在字典中的key,如果不存在的话,将元素作为key,值为列表中元素的count # 字典方法 words = [ 'my', 'skills', 'are', 'poor', 'I', 'am', 'poor', 'I', 'need', 'skills', 'more', 'my', 'ability', 'are', 'so', 'poor' ] dict1 = {} for i in words: if i not in dict1.keys():

用户评论
请输入评论内容
评分:
暂无评论