Skip to content

Instantly share code, notes, and snippets.

@oofnivek
Last active June 29, 2021 02:10
Show Gist options
  • Save oofnivek/b881cf17a6853f70caa58245a5d47549 to your computer and use it in GitHub Desktop.
Save oofnivek/b881cf17a6853f70caa58245a5d47549 to your computer and use it in GitHub Desktop.
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