go - multilevel slices with string indexes -
i have code looks this:
var c [][]string c = append(c, d) c = append(c, l)
assuming both d , l []strings. works, return this:
[["0241025570","0241025571","1102182000"],["0241025570","0241025571","1102182000"]]
how possible structure this:
["d": ["0241025570","0241025571","1102182000"], "l":["0241025570","0241025571","1102182000"]]
what have no longer slice, map of slices. can desired results using following code:
c := make(map[string][]string) c["d"] = d c["l"] = l
depending on usage, may want make copies of d
, l
, instead of using them directly in map:
c := make(map[string][]string) c["d"] = make([]string, len(d)) c["l"] = make([]string, len(l)) copy(c["d"], d) copy(c["l"], l)
Comments
Post a Comment