我正在尝试使用Python标准库集合。
我有一个计数器
>>> c = Counter('achdnsdsdsdsdklaffaefhaew')
>>> c
Counter({'a': 4,
'c': 1,
'h': 2,
'd': 5,
'n': 1,
's': 4,
'k': 1,
'l': 1,
'f': 3,
'e': 2,
'w': 1})
Run Code Online (Sandbox Code Playgroud)
我现在想要的是以某种方式获取此计数器的子集作为另一个Counter对象。像这样:
>>> new_c = do_subset(c, [d,s,l,e,w])
>>> new_c
Counter({'d': 5,
's': 4,
'l': 1,
'e': 2,
'w': 1})
Run Code Online (Sandbox Code Playgroud)
先感谢您。
如果我有一个如下所示的 TypeScript 界面:
interface myInterface {
prop1: string;
prop2: string;
prop3: number;
prop4: boolean;
..
..
..
prop30: string
}
Run Code Online (Sandbox Code Playgroud)
我想创建一个实现的类myInterface,但我只知道详细的方法,如下所示:
class MyClass implements myInterface {
prop1;
prop2;
prop3;
prop4;
..
..
prop30;
constructor(data: myInterface) {
this.prop1 = data.prop1;
this.prop2 = data.prop2;
this.prop3 = data.prop3;
this.prop4 = data.prop4;
..
..
this.prop30 = data.prop30;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以使这个语法更短或者有更好的方法从接口实现这样的类?