[Python-checkins] python/nondist/peps pep-0290.txt,1.5,1.6

Just van Rossum just@letterror.com
Sat, 25 Jan 2003 21:24:26 +0100


rhettinger@users.sourceforge.net wrote:

> + Since booleans are a subclass of integers, the matrix would continue
> + to calculate normally, but it will not print as expected.  The list
> + comprehension should be changed to read::
> + 
> +     return [[i==j and 1 or 0 for i in range(m)] for j in range(m)]

Ugh, I don't think we should recommend the and/or shortcut idiom too
much, if at all. In this particular case, I think the following is much
clearer:

    return [[int(i==j) for i in range(m)] for j in range(m)]

Just