我的问题是,我的密钥将具有非固定值,就像在 python 中一样,我们可以这样做:
dict_ = {}
data_ = [{"name": "roy", "text": "yay i got a gift"},{"name": "dep", "text": "my mum gimme a gift"},{"name": "roy", "text": "another gift from my fan"}]
for data in data_:
key = data["name"]
if key in dict_:
dict_[key] += 1 // add more 1 if key already in dict_
else:
dict_[key] = 1 // set dict key with starting value 1
我正在尝试用 golang 做,谢谢
POPMUISE
相关分类