โ† 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 time complexity of checking membership (`x in s`) in a Python set?

    Answer: O(1) average

    Sets are implemented as hash tables, giving average O(1) membership tests compared to O(n) for lists.

  2. What does the `seek(0)` method do on a file object?

    Answer: Moves the file pointer to the beginning

    `seek(0)` repositions the file pointer to byte offset 0, i.e., the start of the file, allowing re-reading from the beginning.

  3. Which of the following creates a shallow copy of a list `L`?

    Answer: L.copy()

    `L.copy()` (or `L[:]`) creates a shallow copy, duplicating the list but not the objects it references.

  4. What does `json.dump(data, f)` do?

    Answer: Serializes data as JSON and writes it to file f

    `json.dump()` serializes a Python object to a JSON-formatted string and writes it directly to an open file object.

  5. What is a frozenset in Python?

    Answer: An immutable set

    A `frozenset` is an immutable, hashable version of a set; it supports set operations but cannot be modified after creation.

  6. Which mode opens a file and raises `FileExistsError` if the file already exists?

    Answer: 'x'

    Mode `'x'` (exclusive creation) opens a file for writing only if it does not already exist, raising `FileExistsError` otherwise.

  7. What is the difference between a list and a tuple in Python?

    Answer: Lists are mutable; tuples are immutable

    The key distinction is mutability: list elements can be changed, added, or removed, while tuple elements are fixed after creation.