Horje
get adjacent cells in grid Code Example
get adjacent cells in grid
x = 5
y = 5
#just add the target x and y to row and col to get adjacent positions
adjacent_positions = [[row + x ,col + y] for row in (-1,0,1) for col in (-1,0,1) if [row + x ,col + y] != [x,y]]
#output
#[[4, 4], [4, 5], [4, 6], [5, 4], [5, 6], [6, 4], [6, 5], [6, 6]]

#NOTE: without the if statement would produce a list including the target x and y

Source: my_brain.me




Python

Related
find order of characters  python Code Example find order of characters python Code Example
replace error with nan pandas Code Example replace error with nan pandas Code Example
Delete the node at a given position 2 in a linked list and return a reference to the head node. The head is at position 0. The list may be empty after you delete the node. In that case, retur Delete the node at a given position 2 in a linked list and return a reference to the head node. The head is at position 0. The list may be empty after you delete the node. In that case, retur
python program to multiplies all the items in a list using function Code Example python program to multiplies all the items in a list using function Code Example
transparancy argument pyplot Code Example transparancy argument pyplot Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7