1. import json
  2. def pretty_print_records(records):
  3. """
  4. Pretty-prints a list of user records in a readable format.
  5. """
  6. if not records:
  7. print("No records to display.")
  8. return
  9. # Use json.dumps with indent for pretty printing
  10. print(json.dumps(records, indent=4))
  11. def fix_user_records(records):
  12. """
  13. Performs quick fixes on user records and pretty-prints the results.
  14. """
  15. fixed_records = []
  16. for record in records:
  17. # Example fix: Correct invalid email addresses
  18. if "email" in record and "@" not in record["email"]:
  19. record["email"] = record["email"].replace("@", "example.com")
  20. print(f"Fixed email for user {record.get('user_id', 'unknown')}")
  21. # Example fix: Standardize phone number format
  22. if "phone" in record:
  23. record["phone"] = record["phone"].replace("-", "")
  24. print(f"Standardized phone number for user {record.get('user_id', 'unknown')}")
  25. fixed_records.append(record)
  26. pretty_print_records(fixed_records)
  27. if __name__ == '__main__':
  28. # Example usage:
  29. user_records = [
  30. {"user_id": 1, "name": "Alice", "email": "aliceexample.com", "phone": "123-456-7890"},
  31. {"user_id": 2, "name": "Bob", "email": "bob@example.com", "phone": "987-654-3210"},
  32. {"user_id": 3, "name": "Charlie", "email": "charlie@example.com", "phone": "555-123-4567"}
  33. ]
  34. fix_user_records(user_records)

Add your comment