create a map with a key of type rune in go

To create a map with a key of type rune in Go, we can use the built-in make() function with the map[rune] syntax. Here's an example:

main.go
// create a map with a key of type `rune`
m := make(map[rune]string)

// add key-value pairs to the map
m['a'] = "apple"
m['b'] = "banana"
m['c'] = "cherry"

// get the value associated with a key
fmt.Println(m['b']) // output: "banana"
237 chars
11 lines

In this example, we created a map m with keys of type rune and values of type string. We added some key-value pairs to the map, and then used the key 'b' to retrieve the value "banana".

related categories

gistlibby LogSnag