In this activity, you are to design and perform an experiment and submit a writeup of your experiment and results. The topic is the semantics of the __contains__ method of the list class, which is used to evaluate a syntax such as
item in data
that determines whether the given item is in the list. Given our knowledge of a list as a sequence of references, we might re-examine the precise semantics of this built-in behavior. There are two possible hypotheses for the symantics of the Python expression, item in data.
Hypothesis (A):
The expression is True if and only if the actual object identified as item is contained within the list.
This hypothesis is consistent with the following implementation being used within the list class.
def __contains__(self, obj):
for element in self:
if elem is obj: # element must actually be this object
return True
return False # did not find a match
Hypothesis (B):
The expression is True if and only if there exists an element in the list that is equivalent to the identified item.
This hypothesis is consistent with the following implementation being used within the list class.
def __contains__(self, obj):
for element in self:
if elem == obj: # element could be anything equivalent to the object
return True
return False # did not find a match
Your job is to perform experiments to conclusively determine which of these hyptotheses is supported by Python's lists. In explaining your solution, give the text of an interpreter session (including Python's responses) that constitutes your experiment. Then clearly state your conclusion and why the experiment supports your conclusion.
You are to complete and submit the following form. Within it, you are to:
One member of the pair must submit to the quiz25a folder of their git repository a single text file, named readme.txt, based upon the format of our provided template.