import json
def pretty_print_records(records):
"""
Pretty-prints a list of user records in a readable format.
"""
if not records:
print("No records to display.")
return
# Use json.dumps with indent for pretty printing
print(json.dumps(records, indent=4))
def fix_user_records(records):
"""
Performs quick fixes on user records and pretty-prints the results.
"""
fixed_records = []
for record in records:
# Example fix: Correct invalid email addresses
if "email" in record and "@" not in record["email"]:
record["email"] = record["email"].replace("@", "example.com")
print(f"Fixed email for user {record.get('user_id', 'unknown')}")
# Example fix: Standardize phone number format
if "phone" in record:
record["phone"] = record["phone"].replace("-", "")
print(f"Standardized phone number for user {record.get('user_id', 'unknown')}")
fixed_records.append(record)
pretty_print_records(fixed_records)
if __name__ == '__main__':
# Example usage:
user_records = [
{"user_id": 1, "name": "Alice", "email": "aliceexample.com", "phone": "123-456-7890"},
{"user_id": 2, "name": "Bob", "email": "bob@example.com", "phone": "987-654-3210"},
{"user_id": 3, "name": "Charlie", "email": "charlie@example.com", "phone": "555-123-4567"}
]
fix_user_records(user_records)
Add your comment