map-go

path: courses/go-course/map-go.md

- **fileName**: map-go
- **Created on**: 2024-09-01 15:59:28

in go map like dictionary in python Example:

dick = { username: "yossef", age : 20 }

Users := make(map[string]string)
Users["us1"] = "yossef"
Users["us2"] = "joo"
Users["us3"] = "fooo"

// or
Users = map[string]string {
	"us1": "yossef",
	"us1": "joo",
	"us2": "foo"
}

checking for key in go if the key is exists that return true and the element If key is not in the map, then elem is the zero value for the map's element type.

elem, ok := m[key]

using another way ot check for key the best way to check

attended := map[string]bool{
    "Ann": true,
    "Joe": true,
    ...
}
if attended[person] { // will be false if person is not in the map
    fmt.Println(person, "was at the meeting")
}

continue:pointer-go.md
before:array-slice.md