Let's say I have several lists. If the number 1 appears at least once, I want to return it as True. If there are no instances of 1 appearing, then it is False. So let's say I have several lists.
[2.0,2.0]
[1.0, 1.0, 2.0, 2.0]
[1.0, 2.0]
[3.0, 1.0]
[3.0, 3.0, 1.0, 1.0]
[3.0, 3.0, 3.0, 3.0]
The outputs would be:
False
True
True
True
True
False
How can I accomplish this?
EDIT: The code example
def is_walkable(i,j,current_board):
# find all the diagonal neighbours of (i,j) that are on board and put them into a list
diagonal_neighbors = [(i+1,j-1),(i+1,j+1),(i-1,j-1),(i-1,j+1)]
# loop over the list of neighbours to see if any of them is empty
neighbor_values = []
for neighbor in diagonal_neighbors:
row = neighbor[0]
col = neighbor[1]
# if there is an empty neighbour, return True, otherwise return False
if on_board(row,col,current_board):
neighbor_values.append(current_board[row,col])
for neighbor in neighbor_values:
if any(neighbor_values) == 1:
return True
else:
return False
and the testing code is:
current_board = initial_board(empty_board)
print(is_walkable(0,1,current_board) == False)
print(is_walkable(2,1,current_board) == True)
print(is_walkable(2,7,current_board) == True)
print(is_walkable(5,0,current_board) == True)
print(is_walkable(5,6,current_board) == True)
print(is_walkable(6,1,current_board) == False)
All outputs should be "True." This is for a game of checkers on an 8x8 board.