Dispatch jobs with tied sorting keys

A dispatch program orders jobs by urgency using the Python code below. Each pair contains a job label followed by its integer urgency level.


A key function returns the value that a sorting utility uses to order each item. Python’s sorted places smaller keys first, and jobs with equal keys retain their original input order.


Python
jobs = [("A", 3), ("B", 5), ("C", 3), ("D", 4)]

def dispatch_key(job):
    return -job[1]

ordered_jobs = sorted(jobs, key=dispatch_key)


Complete the table with each job’s returned key and its position in ordered_jobs, counting the first position as 1. Enter exact integers in every blank.

JobReturned keyDispatch position
A
B
C
D

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Higher-Order Functions Questions: