On 02/10/10 03:36, Tim Chase wrote:
Larry Hudson wrote:
But a minor rearrangement is simpler, and IMHO clearer:

if 'mystring' not in s:
print 'not found'
else:
print 'foundit'
print 'processing'

I've always vacillated on whether that would better be written as Larry
does, or as

if 'mystring' in s
print 'foundit'
print 'processing'
else:
print 'not found'

<cut>

Any thoughts on how others make the choice?

I cases like this when aesthetics are not that much of a deal breaker, I usually put the condition which I think will be the true the majority of the time first. This is not for performance reasons (never tested whether this has any effect) but more documentation like purpose to go from a most expected case to the least expected one. YMMV

--
mph
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to