find the range of all keys in a map in go

To find the range of all keys in a map in Go, you can use the range keyword to loop over the map keys. Here's an example:

main.go
m := map[string]int{
    "a": 1,
    "b": 2,
    "c": 3,
}

var keys []string
for k := range m {
    keys = append(keys, k)
}

fmt.Println(keys) // Output: [a b c]
164 chars
13 lines

In this example, we first create a map m with some key-value pairs. We then declare a variable keys to hold the keys of the map.

We use the range keyword to loop over the keys of the map, and append each key to the keys slice.

At the end of the loop, keys will contain all the keys of the map. You can then use this slice of keys to find the range of the keys in the map.

gistlibby LogSnag