← All POC Flashcard Decks

Data Structures & File Handling Flashcards

7 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Data Structures & File Handling flashcards as text
  1. What is the output of `sorted({'b': 2, 'a': 1, 'c': 3})`?

    Answer: ['a', 'b', 'c']

    `sorted()` on a dictionary iterates over its keys and returns them in sorted order as a list.

  2. Which data structure should you use to count the frequency of each word in a text efficiently?

    Answer: collections.Counter

    `collections.Counter` is a dict subclass designed to count hashable objects, making it ideal for frequency analysis.

  3. What exception is raised when you try to read from a file opened in write-only mode (`'w'`)?

    Answer: UnsupportedOperation

    `io.UnsupportedOperation` (a subclass of `OSError`) is raised when an unsupported operation like reading is attempted on a write-only file.

  4. What does `list.extend([4, 5])` do compared to `list.append([4, 5])`?

    Answer: extend adds each element individually; append adds the list as a single element

    `extend()` unpacks the iterable and adds each item, while `append()` inserts the whole object as a single new element.

  5. What is the output of `tuple([1, 2, 3]) == (1, 2, 3)`?

    Answer: True

    `tuple([1, 2, 3])` constructs the tuple `(1, 2, 3)`, which compares equal to the literal `(1, 2, 3)`.

  6. Which `os` module function returns the current position of the file pointer?

    Answer: f.tell()

    `f.tell()` returns the current byte offset of the file pointer from the beginning of the file.

  7. In a Python dict, what happens when you assign a value to an existing key?

    Answer: The value is overwritten

    Dictionaries enforce unique keys; assigning to an existing key replaces its value in-place.