I have 2 dimensional array on golang something like
array which contains [1,2,3,4]
[2,3,4,5]
[3,4,5,6]
and I want to join the array columns i.e the result should be
1,2,3
2,3,4
3,4,5
4,5,6
my approach is something like this to create 4 arrays and do something like this:
a := []int{}
for _, row := range array {
append (a,array[1])
append (b,array[2])
append (c,array[2])
append (d,array[2])
}
and then join those arrays something like this
fmt.Println(strings.Join(a[:], ","))
fmt.Println(strings.Join(b[:], ","))
fmt.Println(strings.Join(c[:], ","))
fmt.Println(strings.Join(d[:], ","))
my question if there are an option to access the array by columns not by row or if there are more usful way to do this?
question from:
https://stackoverflow.com/questions/66054903/joining-2-dimensional-array-by-columns 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…