newbie Q: sequence membership
saccade
trivik at gmail.com
Sat Nov 17 02:02:12 EST 2007
>>> a, b = [], []
>>> a.append(b)
>>> b.append(a)
>>> b in a
True
>>> a in a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded in cmp
>>>
>>> a is a[0]
False
>>> a == a[0]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: maximum recursion depth exceeded in cmp
----------
I'm a little new to this language so my mental model on whats going on
may need to be refined.
I expect "a in a" to evaluate to "False". Since it does not it may be
that while checking equality it uses "==" and not "is". If that is the
reason then the question becomes why doesn't "a == a[0]" evaluate to
"False"? As a side, and if that is the reason, is there a version of
"in" that uses "is"? "a is in a" does not work.
Thankx,
Trivik
More information about the Python-list
mailing list