Python's list.__contains__ method has semantics that check for whether any element of the list is equivalent to the given parameter. This can be demonstrated with the following experiment:
>>> x = range(5) >>> y = range(5) >>> print id(x) 3695160 >>> print id(y) 3689488 >>> x == y True >>> x is y False >>> sample = [ x ] >>> print y in sample TrueNotice that the sample list has x as an element, yet it reports the distinct list y to be in the list, because y is equivalent to x. Had the semantics been looking for the precise identity, the last containment query would have returned False.
This is a boolean test to see whether I live in the same actual house as you (that is, if we are housemates).
This is a boolean test to see whether you and I live in houses that are considered to be "equivalent" to each other (even though they may actually be two distinct houses). The notion of equivalence would have to be defined by the House class, perhaps capturing houses that have a similar blueprint or similar market values.
This assignment statement would be used if I were moving into your house. Notice that the identity of yourHouse is unchanged by this assignment. It is myHouse that has changed.
This creates a new house for my use. That house is a "shallow" copy of your house. There is not really any true real-world analogy of such a shallow copy, but if there were it would mean that our two houses share the same phone line, the same utilities, and presumably the same furniture (however that might work).
This creates a new house for my use, as a "deep" copy of your house. My house would be its own house, modeled precisely upon the design of your house, including furnishings that are copies of your own, right down to the food inside the refrigerator inside the kitchen.
This (re)assigns the notion of \lstinline!yourHouse!
to be a reference to the existing house that I am
using. After the assignment, we will both be living
in what was originally my house.
The problem stems from the interpretation of the condition
if not index: # nothing sent by caller
When index is None, this properly
triggers the
default behavior. However, when index is an
integer, this
expression is evaluated such that the value 0 is
treated
as False and all nonzero values are
True.
Unfortunately, this means that an explicit call of
pop(0)
inadvertently deletes the last element of the list (rather than
the first).