James Stroud: > import operator > srch = [(i,j) for i in [-1,0,1] for j in [-1,0,1] if (i,j) != (0,0)] > is_adj = reduce(operator.or_, [ary[row+i][col+j] for (i,j) in srch]])
Or maybe (untested), Python V.2.5: srch = [(i,j) for i in [-1,0,1] for j in [-1,0,1] if (i,j) != (0,0)] is_adj = any(ary[row+i][col+j] for (i,j) in srch) Or: is_adj = any(ary[row+i][col+j] for i in [-1,0,1] for j in [-1,0,1] if (i,j) != (0,0)) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list