Bucket Support Tickets by Priority

Easy ⏱ 8 min 78% acceptance ★★★★☆ 4.4
Write a function bucket_tickets(tickets) where tickets is a list of dicts like {"id": 1, "priority": "High"}. Return a dict mapping each priority string to a list of ticket ids with that priority, preserving the order tickets appear in the input.

Examples

Example 1
Input
bucket_tickets([{'id': 1, 'priority': 'High'}, {'id': 2, 'priority': 'Low'}, {'id': 3, 'priority': 'High'}])
Output
{'High': [1, 3], 'Low': [2]}
Explanation

Group ticket ids under their priority.

Constraints

  • Preserve first-seen order within each bucket.

Topics

Dictionariesbusiness logicgrouping

Companies

ServiceNowSalesforce

Hints

Hint 1

`buckets.setdefault(t["priority"], []).append(t["id"])` for each ticket.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.