Last active
June 29, 2021 02:10
-
-
Save oofnivek/b881cf17a6853f70caa58245a5d47549 to your computer and use it in GitHub Desktop.
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" | |
) | |
type Student struct { | |
FirstName string | |
LastName string | |
} | |
func main() { | |
var classes = make(map[string][]Student) | |
var s []Student | |
t := Student{FirstName:"Harry", LastName:"Potter"} | |
s = append(s,t) | |
t = Student{FirstName:"Ronald", LastName:"Weasley"} | |
s = append(s,t) | |
classes["grade1"] = s | |
s = nil | |
t = Student{FirstName:"Cedric", LastName:"Diggory"} | |
s = append(s,t) | |
t = Student{FirstName:"George", LastName:"Weasley"} | |
s = append(s,t) | |
classes["grade2"] = s | |
for key, value := range classes { | |
fmt.Println("key=", key) | |
arr := value | |
for z:=0; z<len(arr); z++ { | |
student := arr[z] | |
fmt.Println("FirstName=", student.FirstName, "LastName=", student.LastName) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment