Skip to content

Instantly share code, notes, and snippets.

@shockalotti
Last active August 29, 2015 14:01
Show Gist options
  • Save shockalotti/7bb097cf35df0987ff0d to your computer and use it in GitHub Desktop.
Save shockalotti/7bb097cf35df0987ff0d to your computer and use it in GitHub Desktop.
Go Golang - basic map function #2
package main
import "fmt"
func main() {
elements:= make(map[string]string)
elements["H"] = "Hydrogen"
elements["He"] = "Helium"
elements["Li"] = "Lithium"
elements["Be"] = "Beryllium"
elements["B"] = "Boron"
// check that the element exists before trying to print it
if name, ok:=elements["Li"]; ok{
fmt.Println(name,ok)
} else {
fmt.Println("There's no element with that symbol")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment