newbie Q: sequence membership

Sells, Fred fred.sells at adventistcare.org
Mon Nov 19 16:06:36 EST 2007


> >>> a, b = [], []
> >>> a.append(b)
> >>> b.append(a)
did you perhaps mean a.append('b'); b.append('a'); otherwise this seems pretty advanced for a newbie


> >>> 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
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 



More information about the Python-list mailing list