39 lines
815 B
Go
39 lines
815 B
Go
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)
|
|
}
|
|
}
|