def flip_square(square, direction):
    """Flip square in left or up direction."""
    if direction == 'left':
        return [
            row[::-1] for row in square
        ]
    elif direction == 'up':
        return [
            row[:]
            for row in square[::-1]
        ]