declaration of variables?

Andrew Bennetts andrew-pythonlist at puzzling.org
Sun Feb 16 18:33:32 EST 2003


On Sun, Feb 16, 2003 at 09:36:00PM +0100, Andr? Jonsson wrote:
> Jp Calderone wrote:
> >
> >  I don't understand what this even means.  If the error isn't 
> >  *detectable*,
> >it obviously isn't even an error.
> 
> Hmm, how about this example: if a given function sorts some list, if there 
> is an error in there that doesn't cause a run-time error. How is it 
> possible to detect this without having to write the whole routine once more 
> and compare the results? (which, of course, is an error-prone process).

def test_sorted(seq):
    prev = seq[0]
    for elem in seq[1:]:
        assert elem >= prev
        prev = elem

-Andrew.






More information about the Python-list mailing list