我已按照this link上指示的方向使用let data = [{
assigned_user: {
name: 'Paul',
id: 34158
},
doc_status: "processed"
},
{
assigned_user: {
name: 'Simon',
id: 48569
},
doc_status: "processed"
},
{
assigned_user: {
name: 'Simon',
id: 48569
},
doc_status: "processed"
}
];
let res = [];
for (let user of JSON.stringify(data).match(/("name":)"\w+(?=")/g).map(user => user.replace(/["]|name":/g, ""))) {
if (!res.find(({user: _name}) => _name === user))
res.push({user, count: 1})
else
++res.find(({user: _name}) => _name === user).count
}
console.log(res);
方法检查字符串是否为数字,但对我来说失败了。
我只是在尝试:
.isdigit()
打印:
print("final weight:", weight)
if weight.isdigit() == True:
print("yes")
if weight.isdigit() == False:
print("weight is not a digit")
我很困惑,为什么这会失败,因为final weight: 1,873
weight is not a digit
实际上是一个数字。
更新
使用RegEx工作。我只是这样做:
1,873