Complete the code to create a map that stores string keys and integer values.
myMap := make(map[string][1])The map stores keys of type string and values of type int, so the value type must be int.
Complete the code to add a key-value pair to the map.
myMap[[1]] = 10
The key must be a string, so it should be in quotes like "apple".
Fix the error in the code to check if a key exists in the map.
value, [1] := myMap["banana"]
In Go, the second value returned when accessing a map is conventionally named ok to indicate if the key exists.
Fill both blanks to create a map that counts word occurrences only if the word length is greater than 3.
wordCount := map[string]int{}
for _, word := range words {
if len(word) [1] 3 {
wordCount[word] [2] wordCount[word] + 1
}
}== instead of > in the condition.== instead of = for assignment.The condition checks if the word length is greater than 3 using >. To update the count, use = to assign the incremented value.
Fill all three blanks to create a map comprehension that stores uppercase words as keys and their lengths as values for words longer than 4 letters.
result := map[string]int{}
for _, word := range words {
if len(word) [1] 4 {
result[[2]] = [3]
}
}The condition uses > to check length. The key is the uppercase word using strings.ToUpper(word). The value is the length of the word using len(word).
