Create a map of string to List

前端 未结 3 1959
小蘑菇
小蘑菇 2020-12-08 04:10

I\'d like to create a map of string to container/list.List instances. Is this the correct way to go about it?

package main

import (
    \"fmt\"         


        
3条回答
  •  执念已碎
    2020-12-08 04:28

    Whenever I've wanted to use a List I've found that a slice was the right choice, eg

    package main
    
    import "fmt"
    
    func main() {
        x := make(map[string][]string)
    
        x["key"] = append(x["key"], "value")
        x["key"] = append(x["key"], "value1")
    
        fmt.Println(x["key"][0])
        fmt.Println(x["key"][1])
    }
    

提交回复
热议问题