Complete the code to read a log file line by line.
with open('system.log', '[1]') as file: for line in file: print(line.strip())
The mode 'read' opens the file for reading its contents line by line.
Complete the code to filter log lines containing the word 'ERROR'.
error_lines = [line for line in log_lines if '[1]' in line]
Filtering lines with 'ERROR' helps identify critical issues in logs.
Fix the error in the code to parse timestamps from log entries.
from datetime import datetime log_time = datetime.strptime(log_entry['timestamp'], '[1]')
The format '%Y-%m-%d %H:%M:%S' matches timestamps like '2024-06-01 14:30:00'.
Fill both blanks to create a dictionary of IP addresses and their counts from logs.
ip_counts = {ip: [1] for ip in ip_list if ip [2] ip_list}Counting occurrences of each IP with ip_list.count(ip) and checking membership with in builds the dictionary correctly.
Fill all three blanks to filter logs by severity and create a summary dictionary.
summary = [1] for entry in logs if entry['severity'] [2] 'high' and entry['status'] [3] 'open'
The dictionary comprehension uses {entry['id']: entry['message']} to map IDs to messages, filters where severity is 'high' (==) and status is not 'open' (!=).