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 dictionarywhere keys are the string codes ("error", "info"). The values should be a LIST of the respective numerical codes.
grouped = {} - Useinside a loop to guarantee a list exists for each string code before calling
.setdefault()..append(num) - Print.
grouped
main.py
main.py
Ctrl + Enter