Complete the code to open a JSON file named 'data.json' for reading.
with open('data.json', [1]) as file: data = file.read()
To read a file, you use mode 'r'.
Complete the code to load JSON data from a file object named 'file'.
import json data = json.[1](file)
dump or dumps which are for writing JSON.loads which expects a string, not a file.The function json.load() reads JSON data from a file object.
Fix the error in the code to write a Python dictionary 'data' to a JSON file named 'output.json'.
import json with open('output.json', 'w') as file: json.[1](data, file)
load or loads which are for reading JSON.dumps without writing the string to the file.Use json.dump() to write JSON data to a file.
Fill both blanks to create a dictionary comprehension that maps each word to its length, but only for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2]
The dictionary maps each word to its length using len(word). The condition filters words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that converts keys to uppercase, keeps values, and filters only items where value is greater than 10.
data = {'a': 5, 'b': 15, 'c': 20}
result = { [1]: [2] for k, v in data.items() if [3] }k > 10.The comprehension creates a new dictionary with uppercase keys, original values, and includes only items where the value is greater than 10.