sos := make([][]string,3)ss := [["name","place","thing"],["name","place","thing"],["name","place","thing"]]让 sos 成为 [["name","name"],["place","place"],["thing","thing"] 我如何附加名称、地点和事物字段?最好使用从 ss 到 sos 的 for 循环? for i:=0;i<len(sos);i++ { sos[i] = append(sos[i],ss[0]) }上面的 for 循环只能附加第一个变量,即从 ss 到 sos 的“名称”,我怎样才能附加其余的变量呢?
1 回答
Cats萌萌
TA贡献1805条经验 获得超9个赞
你想这样做吗?
package main
import (
"fmt"
)
func main() {
sos := make([][]string, 3)
ss := [][]string{ []string{"name", "place", "thing"}, []string{"name", "place", "thing"}, []string{"name", "place", "thing"} }
for i := range ss {
for j := range ss[i] {
sos[i] = append(sos[i], ss[j][i])
}
}
fmt.Println(sos)
}
输出:
[[姓名姓名][地方地方][东西东西]]
- 1 回答
- 0 关注
- 101 浏览
添加回答
举报
0/150
提交
取消