Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!postnews.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: checking if a list is empty Date: Wed, 11 May 2011 08:26:53 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 35 Message-ID: References: <200e93c2-6b87-4113-9c6f-85815e51ea77@28g2000yqu.googlegroups.com> <4dc4b3c5$0$29991$c3e8da3$5496439d@news.astraweb.com> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1305116814 3654 127.0.0.1 (11 May 2011 12:26:54 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 11 May 2011 12:26:54 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5109 Hans Georg Schaathun wrote: > li == [] is as explicit as it gets, and > leaves no room for doubt. I was about to write, "this fails if li is an instance of a subclass of list", but then I tried it. I was astounded to discover that: class MyList(list): "I'm a subclass" li = MyList() print li == [] print [] == li prints True, twice! I expected them both to be false. In fact, the docs (http://tinyurl.com/3qga3lb) explicitly say: > If both are numbers, they are converted to a common type. Otherwise, > objects of different types always compare unequal Since these are different types, i.e. print type(li) print type([]) print type(li) == type([]) prints False I conclude that li == [] should have returned False. Either I'm not understanding things correctly, or this is a bug.