Python code is not optimised.
def do_something(board):
res = []
for i, p in enumerate(board):
for d in directions:
res.append(board[d[i]])
return res
Run
should be written as list comprehension:
do_something(board):
return [d[i] for d in directions for i, p in enumerate(board)]
Run
Comprehensions in Python are much faster than ordinary loops. You will gain
2-3x perfomance boost.
