Complete the code to iterate over the map and print keys.
for [1] := range myMap { fmt.Println([1]) }
In Go, when iterating over a map, the first variable is the key.
Complete the code to iterate over the map and print keys and values.
for [1], value := range myMap { fmt.Println([1], value) }
The first variable in the range loop is the key, which we name 'key' here.
Fix the error in the code to correctly iterate over the map and print keys and values.
for key, [1] := range myMap { fmt.Println(key, [1]) }
The second variable in the range loop is the value, so use 'value'.
Fill both blanks to create a map comprehension that stores lengths of keys longer than 3 characters.
lengths := map[string]int{}
for [1], [2] := range myMap {
if len([1]) > 3 {
lengths[[1]] = len([1])
}
}Use 'key' and 'value' to iterate over the map. The key is used to check length and store in the new map.
Fill all three blanks to create a map that stores uppercase keys with their values if the value is greater than 10.
filtered := map[string]int{}
for [1], [2] := range myMap {
if [2] > 10 {
filtered[strings.ToUpper([1])] = [2]
}
}Use 'key' and 'value' to iterate. Check if value > 10, then store with uppercase key and value.