小编man*_*ich的帖子

元素计数字典

我想创建一个包含的字典{x,list.count[x]}.但是,在尝试执行我的代码时,我一直遇到错误:

apple = ['variant', 'variant', 'variant2.0', 'variant 3.0']

pear = {}

for x in apple:
    pear.update({x,apple.count(x)})
Run Code Online (Sandbox Code Playgroud)

错误是cannot convert dictionary update sequence element#0 to a sequence.任何建议?

python dictionary

2
推荐指数
1
解决办法
50
查看次数

标签 统计

dictionary ×1

python ×1