Complete the code to get the value for key "apple" from the dictionary.
let fruits = ["apple": 3, "banana": 5] let count = fruits[[1]]
The key "apple" is used to access its value in the dictionary.
Complete the code to provide a default value of 0 when the key is missing.
let fruits = ["apple": 3, "banana": 5] let count = fruits["orange", default: [1]]
Using default: 0 returns 0 if the key is not found.
Fix the error in updating the dictionary value safely.
var fruits = ["apple": 3, "banana": 5] fruits["apple"] = fruits["apple"]! [1] 2
We add 2 to the existing value for key "apple".
Fill both blanks to create a dictionary with squares of numbers greater than 3.
let squares = [[1]: [2] for num in 1...5 if num > 3]
The dictionary keys are numbers and values are their squares for numbers greater than 3.
Fill all three blanks to filter dictionary items with values greater than 4 and map keys to uppercase.
let fruits = ["apple": 3, "banana": 5, "cherry": 7] let filtered = [[1]: [2] for (key, value) in fruits where value [3] 4]
Keys are converted to uppercase, values are kept, and only items with values greater than 4 are included.
