Map in Go

Declare a map:

1
2
3
4
5
6
7
8
9
// Nil map: Read-Only
var di map[string]string


dict := map[string]string{
	"good":    "iyi",
	"great":   "harika",
	"perfect": "mükemmel",
}

Delete an element of the map using delete builtin:

1
delete(dict, "awesome")

Retrieve an value from map:

1
2
3
if value, ok := dict["great"]; ok {
    fmt.Printf("%q found in dict", value)
}

Iterate through map elements:

1
2
3
for key, value := range dict {
    fmt.Println(key, value)
}