Keep validated data valid after the caller changes its input

A Python importer receives a caller-owned list of dictionaries. Every dictionary initially contains a name string and a quantity integer. Validation requires a nonempty name and a quantity from 0 through 500. Strings and integers are immutable, but lists and dictionaries are mutable. After the import returns, the caller may change its list or any original dictionary. There are no concurrent changes during import.


Which strategies preserve the imported names and quantities as the validated snapshot despite those later caller changes? Select every correct strategy.

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Defensive Design Questions: