Simple map exaple
This commit is contained in:
parent
c959795558
commit
e781ac8bb4
38
maps/go.go
Normal file
38
maps/go.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Vertex struct {
|
||||||
|
X, Y float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
m := make(map[string]Vertex)
|
||||||
|
m["hello world"] = Vertex{12.2, 32.22}
|
||||||
|
m["another place"] = Vertex{X: 12}
|
||||||
|
m["bilbo baggins"] = Vertex{}
|
||||||
|
fmt.Println(m)
|
||||||
|
delete(m, "bilbo baggins")
|
||||||
|
delete(m, "frodo baggins")
|
||||||
|
if v, ok := m["another place"]; ok {
|
||||||
|
fmt.Printf("%v %v\n", v, ok)
|
||||||
|
}
|
||||||
|
fmt.Printf("%v\n", m)
|
||||||
|
|
||||||
|
n := make(map[string]map[string]int)
|
||||||
|
my_name := "stephen m. mcquay"
|
||||||
|
n[my_name] = make(map[string]int)
|
||||||
|
n[my_name]["weight"] = 197
|
||||||
|
n[my_name]["age"] = 31
|
||||||
|
n["michael m. mcquay"] = map[string]int{"weight": 210, "age": 30}
|
||||||
|
fmt.Printf("%v\n", n)
|
||||||
|
|
||||||
|
for k := range n {
|
||||||
|
fmt.Printf("'%v'\n", k)
|
||||||
|
}
|
||||||
|
for k, v := range n {
|
||||||
|
fmt.Printf("'%v' : %v\n", k, v)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user