Skip to content

Commit 4a3fb02

Browse files
Merge pull request #59 from Aashna-Agrawal/patch-1
Create map.go
2 parents 5c72362 + b9eb743 commit 4a3fb02

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

advanced/map.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func main() {
8+
myMap := make(map[string]string)
9+
10+
//Insertionn in a map
11+
myMap["A"] = "apple"
12+
myMap["B"] = "ball"
13+
myMap["C"] = "cat"
14+
15+
//Traverse a map
16+
fmt.Println("Printing Map..........",)
17+
for key, value := range myMap {
18+
fmt.Println("Key: ", key, " Value: ", value)
19+
}
20+
21+
//Delete a key-value pair from a map
22+
//Deleting Key: "C" from map
23+
fmt.Println("Deleting a key from Map..........",)
24+
delete(myMap, "C")
25+
26+
//Find the value associated with a key
27+
fmt.Println("Finding a key from Map..........",)
28+
fmt.Println("Value for key 'A': ", myMap["A"])
29+
}
30+

0 commit comments

Comments
 (0)