I thought I had list comprehensions more or less figured out but then I was presented with this line of code from another question.
Pythonic and efficient way of finding adjacent cells in grid
I've changed the code to just return the 8 tuples that make up the adjacent tiles (when added to our current tile).
[(i, j) for i in (-1,0,1) for j in (-1,0,1) if i != 0 or j != 0]
produces:
[(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
The statement actually makes sense to me except for the last part where the conditional is made:
if i != 0 or j != 0
If we're trying to find adjacent cells, and we want to omit the cell that we are in, shouldn't the conditional part read AND instead of OR?
Like this:
if i != 0 and j != 0
Instead if I put AND in there, I get only these tuples returned:
(-1, -1), (-1, 1), (1, -1), (1, 1)
Just seems counter intuitive to me.