python count duplicate in list

前端 未结 7 592
遇见更好的自我
遇见更好的自我 2020-12-11 08:42

i have this list:

[\'Boston Americans\', \'New York Giants\', \'Chicago White Sox\', \'Chicago Cubs\', \'Chicago Cubs\', \'Pittsburgh Pirates\', \'Philadelph         


        
7条回答
  •  盖世英雄少女心
    2020-12-11 09:12

    Try this:

    new_list =  ['a', 'b', 'a']
    new_dict = {}
    for i in new_list:
     new_dict[i]=new_list.count(i)       
    print(new_dict)
    
    Result - {'a': 2, 'b': 1}
    

提交回复
热议问题