我有一个列表Python,它是一个包含字典的字典.
{'METTS MARK': {'salary': 365788, 'po': 1}, 'HARRY POTTER':{'salary': 3233233, 'po': 0}
Run Code Online (Sandbox Code Playgroud)
如何计算记录数'po' = 1?
我试过这个:
sum = 0
for key, values in DIC:
if values[po] == 1:
sum = sum + 1
Run Code Online (Sandbox Code Playgroud)
但它返回: too many values to unpack
提前致谢
我有这个类的构造函数以String和Arraylist作为参数;
class Foo{
String ide;
ArrayList list;
public TypeOperator(String ide, ArrayList list){
this.ide = ide;
this.list = list;
}
}
Run Code Online (Sandbox Code Playgroud)
所以当我像下面这样初始化类时:
Foo one = new Foo("boo", []);
Run Code Online (Sandbox Code Playgroud)
它给出了错误。好吧,我可以这样做以使其工作:
ArrayList empty = new ArrayList();
Foo one = new Foo("boo", empty);
Run Code Online (Sandbox Code Playgroud)
有什么理由使第一个解决方案不起作用?还是有办法进行一些更改以使其起作用?谢谢