Skills101
← All practice quizzes

Quiz: Sorting, heapq and bisect

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

Sort records by several keys, understand why Python's sort is stable, use heapq as a priority queue and for top-k problems, and use bisect for fast binary search in a sorted list.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    What does this print?

    data = [("b", 2), ("a", 2), ("c", 1)]
    print(sorted(data, key=lambda t: (-t[1], t[0])))
    
  2. Question 2

    What does it mean that Python's sort is stable?

  3. Question 3

    You sort by name first and then by marks with a second stable sort. Which key decides the final order most?

  4. Question 4

    After heapq.heapify(a), what is guaranteed?

  5. Question 5

    What does this print?

    import heapq
    h = []
    for x in [5, 1, 4, 2]:
        heapq.heappush(h, x)
    print(heapq.heappop(h), heapq.heappop(h))
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →