Back to Lesson

Data Aggregation

Group data sequentially utilizing dictionary default values.

Instructions

  • You have a list of paired logs:
    logs = [("error", 404), ("info", 200), ("error", 500)]
  • Build a dictionary
    grouped = {}
    where keys are the string codes ("error", "info"). The values should be a LIST of the respective numerical codes.
  • Use
    .setdefault()
    inside a loop to guarantee a list exists for each string code before calling
    .append(num)
    .
  • Print
    grouped
    .
main.py
main.py