英文:
create map of string slice in go
问题
我正在尝试使用GO语言的代码创建一个字符串切片的映射。
newMap := map[string][]string{
"first": {"good", "bad"},
"second": {"top", "bottom"},
}
看起来这不是正确的方式,有什么问题吗?
英文:
I am try to create a map of string slice with the code in GO
newMap := map [string][]string{
"first" : {
"good", "bad"
},
"second" : {
"top", "bottom"
}
}
It seems not to be the right way, what is the wrong with it?
答案1
得分: 5
你必须在每个初始化列表的末尾添加逗号 ,
。
newMap := map[string][]string{
"first": {
"good", "bad",
},
"second": {
"top", "bottom",
},
}
你可以在这里找到一个可运行的示例。
英文:
You have to add a comma ,
at the end of each initializer list.
newMap := map [string][]string{
"first" : {
"good", "bad",
},
"second" : {
"top", "bottom",
},
}
You can find a working example here.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论