On 01/01/2013 12:59 PM, Ed Leafe wrote:
On Jan 1, 2013, at 2:29 PM, Carey Gagnon <[email protected]> wrote:
2) In Python, testing for empty lists (or tuples, or dicts, or strings) by
comparing their length to zero is not needed, and is frowned upon. Instead,
take advantage of the fact that empty lists evaluate to boolean False. In other
words, these two statements are equivalent, but the second is more Pythonic:
if len(somelist) == 0:
# and
if not somelist:
Though as a counterpoint this is one of those Pythonisms I do not
totally agree with, if for no other reason then it breaks two of the Zen
of Python rules:
Explicit is better than implicit.
Readability counts.
and doing an explicit test is covered by a third
Although practicality beats purity.
Since what you are testing may have been declared in code well away from
where you test it, the explicit test tends to be self documenting.
--
Adrian Klaver
[email protected]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[email protected]