create map of string slice in go

huangapple go评论91阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2015年6月29日 17:40:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/31112426.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定