Complete the code to flush the output buffer immediately.
print('Hello, world!', end='') import sys sys.stdout.[1]()
The flush() method forces the output buffer to be written immediately.
Complete the code to open a file with buffering disabled.
with open('log.txt', 'w', buffering=[1]) as f: f.write('Log start\n')
Setting buffering=0 disables buffering for the file.
Fix the error in flushing the file output.
f = open('data.txt', 'w') f.write('Data') f.[1]()
The correct method to flush a file's buffer is flush().
Fill both blanks to create a dictionary of word lengths for words longer than 3 letters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3}
The dictionary comprehension uses len(word) for values and filters words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.
data = {'a': 1, 'b': 0, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }The dictionary comprehension uses uppercase keys, values as is, and filters values greater than zero.
