1. import json
  2. from collections import defaultdict
  3. def deduplicate_http_responses(response_list):
  4. """
  5. Deduplicates a list of HTTP response records.
  6. Args:
  7. response_list (list): A list of dictionaries, where each dictionary
  8. represents an HTTP response record.
  9. Returns:
  10. list: A new list containing only the unique HTTP response records.
  11. """
  12. seen = set() # Use a set to track seen responses
  13. unique_responses = []
  14. for response in response_list:
  15. # Convert the response to a tuple of its key fields for hashing
  16. # You can customize these keys based on what defines a duplicate
  17. response_tuple = tuple(response.get("url", "") + "," + response.get("method", "") + "," + response.get("status_code", ""))
  18. if response_tuple not in seen:
  19. unique_responses.append(response)
  20. seen.add(response_tuple)
  21. return unique_responses

Add your comment