今天竟然犯傻了,竟然理解错了

list1=[1,2,3,'a','a','c',4,6,2,3,1,1,1,1]
dict1={}
for key in list1:
dict1[key]=dict1.get(key,0)+1
print(dict1)

output:

{'a': 3, 1: 5, 2: 2, 3: 2, 'c': 1, 4: 1, 6: 1}

相关文章:

  • 2021-08-08
  • 2022-03-09
  • 2022-12-23
  • 2022-02-17
  • 2022-01-25
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2021-12-06
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案