Created
September 30, 2014 18:06
-
-
Save jochasinga/f2229382cdef14d01763 to your computer and use it in GitHub Desktop.
Embedded Maps in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
creatures := make(map[string]map[string]string) | |
creatures = map[string]map[string]string{ | |
"P" : map[string]string{ | |
"name" : "Pokemon", | |
"power" : "lightning", | |
"color" : "yellow", | |
}, | |
"U" : map[string]string{ | |
"name" : "Unicorn", | |
"power" : "flying", | |
"color" : "white", | |
}, | |
"F" : map[string]string{ | |
"name" : "Furby", | |
"power" : "nagging", | |
"color" : "various", | |
}, | |
"G" : map[string]string{ | |
"name" : "Gopher", | |
"power" : "digging", | |
"color" : "blue", | |
}, | |
} | |
for _, v := range creatures { | |
fmt.Println(v["name"], "with the power of", v["power"]) | |
} | |
fmt.Printf("F's name is %s", creatures["F"]["name"]) | |
fmt.Printf("G's color is %s", creatures["G"]["color"]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment