Last active
September 23, 2016 02:09
-
-
Save FilBot3/32bb95a51d6b980db1866d5e2bea9e4b to your computer and use it in GitHub Desktop.
Nested Maps in Slices with GO.
This file contains hidden or 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() { | |
| // Initalize a Slice that holds Maps of strings | |
| slice_1 := make([]map[string]string, 0) | |
| // Initialize a Map of string keys and string values | |
| map_1 := make(map[string]string) | |
| // Assign a Key, key, and a value, farts | |
| map_1["key"] = "farts" | |
| map_1["stuff"] = "more" | |
| map_2 := make(map[string]string) | |
| map_2["key"] = "things" | |
| // Assign slice_1 to take the return of append, appending map_1 to slice_1 | |
| slice_1 = append(slice_1, map_1) | |
| slice_1 = append(slice_1, map_2) | |
| fmt.Println(slice_1) | |
| // Access the value of the Hash map | |
| fmt.Println(slice_1[0]["key"]) | |
| } |
This file contains hidden or 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
| $ go run nested_slices.go | |
| [map[key:farts stuff:more] map[key:things]] | |
| farts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment