小编Moh*_*del的帖子

我如何从字典的键中计算对象?

我有这本词典:

dict={"asset":[("S3","A1"),"S2",("E4","E5"),("E1","S1"),"A6","A8"], 
"Rank":lirank,"number_of_attributes": }
Run Code Online (Sandbox Code Playgroud)

跳过“排名”。

? 想要计算“资产”键的对象并将其作为列表附加到“number_of_attributes”。

?我想要的输出是:

"number_of_attributes":[2,1,2,2,1,1]
Run Code Online (Sandbox Code Playgroud)

这意味着资产的第一个对象(“S3”,“A1”)有 2 个项目,第二个(“S2”)是 1 个项目......我想用 for 循环写它,但任何交换都是可以接受的! !

python dictionary count

3
推荐指数
1
解决办法
65
查看次数

标签 统计

count ×1

dictionary ×1

python ×1