newbie Q: sequence membership

saccade trivik at
Mon Nov 19 07:32:12 CET 2007

On Nov 17, 3:40 am, "Gabriel Genellina" <gagsl-... at>
> You can write your own membership test based on identity ('is'):
Thank you for the practical (usable) advice and explanation of the
'==' operator.

On Nov 17, 4:35 am, John Machin <sjmac... at> wrote:
> And that can be done by reading the fine manual, specifically
This is true. I was being lazy by posting but have been pleasantly
surprised by the detailed responses. For the most, Python's beautiful
syntax has thus far required minimal thought of me. Programs feel more
like pseudo code than code and I may have gotten carried away.

On Nov 17, 4:35 am, John Machin <sjmac... at> wrote:
> Worse: Consider z = ['A1', 'Z9']. It's highly likely that when x ==
> 'A1', "x is_in z" is True -- because an unguaranteed implementation-
> dependent caper caches or "interns" some values, so that x and z[0]
> are the same object. Try explaining that to the novices!!
I am not a programmer so I feel odd commenting about language design
decisions. When my Prof. introduced python the first question that
popped into mind was that since "x=9; y=9; print x is y and x == y"
prints "True" is there a way to change the value of 9? He said that
was silly but after class showed me that statements "True = []" work
but suggested it was harmless and not quite a bug.

So if I am permitted to think of integers as immutable objects with
predefined labels (i.e. the integers used in the text of the program
code) that cannot de or re referenced then what a similar treatment of
characters will look like seams to be an arbitary (a design) decition.

In this vein it seams reasonable to expect 'a'[0] and 'ba'[1] to refer
to the same object. If one follows the convention used with integers
(9 and 9 refer to the same object) then 'ab' and 'ab' would be the
same. An equally reasonable assumption would be that 'ab' and 'ab' are
two different sequences and so not equal (I do not see the problem

Actually this is what you said is left up to the implementation. '=='
seams to add a lot of power but I am not sure where or how (except as
a shortcut in the very special case of strings). Pardon the babble.

On Nov 17, 4:35 am, John Machin <sjmac... at> wrote:
> Do you have a use case for that?
I have a list of lists and want to see if another list is a member of
it. The content of the lists and the way they are related to each
other changes from program to program.

More information about the Python-list mailing list