[Tutor] Help with excetion handing and making my codemore efficient needed please
alan.gauld at btinternet.com
Sat May 19 01:44:08 CEST 2007
"Matt Smith" <matt at mattanddawn.orangehome.co.uk> wrote in message
news:1179525754.12384.28.camel at computer...
>> > Is there a better way of doing this?
>> Perhaps something like this:
>> for n in (x, x+1, x-1):
>> for m in (y, y+1, y-1):
>> if matrix[n, m]:
>> neighbour_count = neighbour_count + 1
> I need to not text matrix[x][y] is there a simple way to
> exclude this from the possible combinations of values
> from the two tuples?
As Luke said you don;t need to exclude it because you
know that it is always True so you can adjust the final
count to take that into consideration. The cost of testing
one extra cell is much less than testing for an exception
for each of the other 8!
Sometimes algorithms can be adjusted slightly to make
life a lot simpler.
More information about the Tutor