Choose a built-in container by operation

Problem

Choose the most direct Python container or standard abstraction for each case, in order: a mutable ordered batch; a fixed coordinate usable as a key; counts by word; unique visited IDs; undo in reverse order; jobs in arrival order; and repeatedly removing the smallest deadline. Give one operation-based reason for every choice.

Reveal answer or reference solution

Use: list for a mutable ordered batch; tuple for a fixed hashable coordinate; dict as a hash map from word to count; set for unique visited IDs and average O(1)O(1) membership; list used as stack for LIFO undo via append/pop; collections.deque for O(1)O(1) queue operations at both ends; and a heapq min-heap for repeated minimum removal in O(log⁡n)O(\log n).

def container_plan() -> tuple[str, ...]:
    return (
        "list",
        "tuple",
        "dict",
        "set",
        "list used as stack",
        "collections.deque",
        "heapq min-heap",
    )

Public tests

  • container_plan() → ('list', 'tuple', 'dict', 'set', 'list used as stack', 'collections.deque', 'heapq min-heap')
Outcome

Previous attempts

Loading attempts saved in this browser…

    Review Screening Results