1
0
Fork 0

Simple map exaple

This commit is contained in:
Stephen M. McQuay 2012-08-01 09:11:55 -06:00
parent c959795558
commit e781ac8bb4
1 changed files with 38 additions and 0 deletions

38
maps/go.go Normal file
View 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)
}
}