[Tutor] Function design

Benno Lang transmogribenno at gmail.com
Tue Oct 27 12:32:20 CET 2009


On Tue, Oct 27, 2009 at 8:21 AM, Dave Angel <davea at ieee.org> wrote:
> I agree with Luke's comments.  But I'd like to point out an apparent bug (I
> haven't tried the code, this is just by inspection).
>
> You use the test
>     if '0' in row[.....]
>
> that's not going to check for a zero value, it's going to check for a zero
> digit character somewhere in the value.  So 504 would also be recognized, as
> well as 540.

I thought this sounded rather fishy, along the following lines:
row is a list, so slicing it returns a list, so 'in' should compare
the list elements (i.e. the strings contained therein) with '0'; this
seems perfectly normal.

I have checked, and thankfully the world is not upside down. It would
only work the way you describe if row was a string, or if 'in' called
itself recursively when it found a list.

HTH,
benno


More information about the Tutor mailing list