gpt4 book ai didi

go - Golang 中有等效的 Guava 表吗?如果不是,在 Go 中正确的做法是什么

转载 作者:数据小太阳 更新时间:2023-10-29 03:10:47 25 4
gpt4 key购买 nike

我想要这样的东西

  1. 表格

  2. map [字符串]表

下面提到了我对 map[string]table 的厌倦,但不确定它是否是正确的方法:

package main

import (
"fmt"
)

type table struct{
a,b []int
c []string
}

func main() {
mytable := make(map[string]table)
var a1 []int
var b1 []int
var c1 []int

a1=append(a1,1)
a1=append(a1,1)
b1=append(b1,2)
c1=append(c1,"Golang")

t1 := table{a1,b1,c1}

mytable["abc"]=t1
}

我需要表格,因为我将使用 CSV 文件的数据。让我知道执行此操作的最佳方法。

最佳答案

您可以创建一个“行”列表,每个“行”包含表格的一行:

type Data struct {
A int
B int
C string
}

func main() {
var table []Data

table = append(table, Data{A: 1, B: 2, C: "foo"})
...
}

关于go - Golang 中有等效的 Guava 表吗?如果不是,在 Go 中正确的做法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52274187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com