Data Ingestion and Transformation
A Python transformation repeatedly checks whether each incoming customer ID appears in a large list of allowed IDs. Order and duplicate entries are irrelevant; which change will MOST reduce membership-check runtime?
Show the answer
Correct answerD. Build a set once and check membership in it
AWhy not this: Sorting repeatedly adds overhead, and the standard membership operation still searches a list linearly.
BWhy not this: Copying adds work and leaves the linear-time membership check unchanged.
CWhy not this: Tuple membership checks remain linear despite the tuple being immutable.
DWhy this is right: A set supports average constant-time membership checks, and building it once amortizes the conversion cost.
Python sets provide average constant-time membership checks, whereas list membership checks take linear time. Converting the list to a tuple does not change the linear search required for membership checks.