The queen can be moved any number of unoccupied squares in a straight line vertically, horizontally, or diagonally, thus combining the moves of the rook and bishop. The queen captures by occupying the square on which an enemy piece sits. (wikipedia: https://en.wikipedia.org/wiki/Queen_(chess)).

## Task:
Write a function ```availableMoves(position)``` which returns possibly moves of chess queen. Returned value should be an ```array``` with possible moves sorted alphabetically, exluded starting position.

For example when input position is ```A1``` return value should be:

```["A2", "A3", "A4", "A5", "A6", "A7", "A8", "B1", "B2", "C1", "C3", "D1", "D4", "E1", "E5", "F1", "F6", "G1", "G7", "H1", "H8"]```

```
     A   B   C   D   E   F   G   H
   + - + - + - + - + - + - + - + - +
1  | Q | x | x | x | x | x | x | x |
   + - + - + - + - + - + - + - + - +
2  | x | x |   |   |   |   |   |   |
   + - + - + - + - + - + - + - + - +
3  | x |   | x |   |   |   |   |   |
   + - + - + - + - + - + - + - + - +
4  | x |   |   | x |   |   |   |   |
   + - + - + - + - + - + - + - + - +
5  | x |   |   |   | x |   |   |   |
   + - + - + - + - + - + - + - + - +
6  | x |   |   |   |   | x |   |   |
   + - + - + - + - + - + - + - + - +
7  | x |   |   |   |   |   | x |   |
   + - + - + - + - + - + - + - + - +
8  | x |   |   |   |   |   |   | x |
   + - + - + - + - + - + - + - + - +
   
Q = queen
x = available move
```

## Input:
- input position can be any type (array, number, string and so on). If input position is not a string then return empty array.
- valid input position is one letter from ```A``` to ```H``` with number from ```1``` to ```8```, for example ```A1```, ```C8```, ```B3```. If input is invalid (for example ```A10``` or ```H0```) then return empty array.

Difficulty: EASY
Tags: Fundamentals

Data structures
Skill types: Data structures

Starter code:
def available_moves(position):
	

Solutions:
from itertools import product
BOARD = set(map(''.join, product('ABCDEFGH', '12345678')))

def available_moves(position):
	if isinstance(position, str) and position in BOARD:
		return sorted((p for p in BOARD - {position} if abs(ord(p[0]) - ord(position[0])) == abs(int(p[1]) - int(position[1])) or position[0] == p[0] or p[1] == position[1]))
	return []


columns = 'ABCDEFGH'

def available_moves(position):
	if not (isinstance(position, str) and len(position) == 2):
		return []
	(c0, r0) = position
	if not ('A' <= c0 <= 'H' and '1' <= r0 <= '8'):
		return []
	(c, r) = (columns.index(c0), int(r0) - 1)
	xs = {(i, r) for i in range(8)}
	xs |= {(c, i) for i in range(8)}
	xs |= {(i, r + c - i) for i in range(8) if 0 <= r + c - i < 8}
	xs |= {(i, r + i - c) for i in range(8) if 0 <= r + i - c < 8}
	xs.remove((c, r))
	return [f'{columns[c]}{r + 1}' for (c, r) in sorted(xs)]


board = {f'{c}{n}' for c in 'ABCDEFGH' for n in '12345678'}

def available_moves(position):
	if not isinstance(position, str) or position not in board:
		return []
	((x, y),) = ((ord(c) - 65, int(n) - 1) for (c, n) in (position,))
	moves = lambda n: ((x, n), (n, y), (x - n, y - n), (x + n, y - n), (x - n, y + n), (x + n, y + n))
	result = {f'{chr(i + 65)}{j + 1}' for n in range(8) for (i, j) in moves(n)}
	return sorted(board & result - {position})


from itertools import chain, count, takewhile
import re

def available_moves(position):
	if not isinstance(position, str) or not re.match('[A-H][1-8]$', position):
		return []

	def converter(g):
		return (chr(x + 65) + chr(y + 49) for (x, y) in g)

	def genTargetedPos(dx, dy):
		return converter(takewhile(lambda p: 0 <= p[0] < 8 and 0 <= p[1] < 8, ((X + n * dx, Y + n * dy) for n in count(1))))
	(X, Y) = (ord(position[0]) - 65, int(position[1]) - 1)
	return sorted(chain(*(genTargetedPos(dx, dy) for dx in range(-1, 2) for dy in range(-1, 2) if dx or dy)))


from_pos = lambda s: (ord(s[0]) - 65, int(s[1]) - 1)
to_pos = lambda i, j: f'{chr(i + 65)}{j + 1}'

def available_moves(position):
	if not (isinstance(position, str) and len(position) == 2 and (position[0] in 'ABCDEFGH') and (position[1] in '12345678')):
		return []
	((x, y), res) = (from_pos(position), [])
	for (k, l) in ((0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)):
		(i, j) = (y + k, x + l)
		while 0 <= i < 8 and 0 <= j < 8:
			res.append(to_pos(j, i))
			(i, j) = (i + k, j + l)
	return sorted(res)


Dict = {'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7}

def toCoord(position):
	if type(position) != str:
		return []
	if position[0] in Dict and 1 <= int(position[1]) <= 8:
		return (Dict[position[0]], int(position[1]) - 1)

def fromCoord(position):
	return chr(64 + position[0] + 1) + str(position[1] + 1)

def available_moves(position):
	try:
		if type(position) == str and len(position) == 2 and (65 <= ord(position[0]) <= 90):
			moves = []
			position = toCoord(position)
			if position == []:
				return moves
			if 0 <= position[0] <= 7 and 0 <= position[1] <= 7:
				i = 1
				for x in range(8):
					if (x, position[1]) != position:
						moves.append(fromCoord((x, position[1])))
				for y in range(8):
					if (position[0], y) != position:
						moves.append(fromCoord((position[0], y)))
				for i in range(1, max(max(7 - position[0], position[0]), max((7 - position[1], position[1]))) + 1):
					if 0 <= position[0] + i <= 7 and 0 <= position[1] + i <= 7:
						moves.append(fromCoord((position[0] + i, position[1] + i)))
					if 0 <= position[0] + i <= 7 and 0 <= position[1] - i <= 7:
						moves.append(fromCoord((position[0] + i, position[1] - i)))
					if 0 <= position[0] - i <= 7 and 0 <= position[1] + i <= 7:
						moves.append(fromCoord((position[0] - i, position[1] + i)))
					if 0 <= position[0] - i <= 7 and 0 <= position[1] - i <= 7:
						moves.append(fromCoord((position[0] - i, position[1] - i)))
				return sorted(moves)
			return []
		return []
	except TypeError:
		return []
print(available_moves('D8'))


def Horizontal(position):
	R = position[1]
	HorizontalMoves = ['A' + R, 'B' + R, 'C' + R, 'D' + R, 'E' + R, 'F' + R, 'G' + R, 'H' + R]
	possible = list(filter(lambda x: x != position, HorizontalMoves))
	return possible

def Vertical(position):
	F = position[0]
	VerticalMoves = [F + str(1), F + str(2), F + str(3), F + str(4), F + str(5), F + str(6), F + str(7), F + str(8)]
	p = list(filter(lambda y: y != position, VerticalMoves))
	return p

def TRtBL(position):
	moves = []
	num = int(position[1])
	ASC_Letter = ord(position[0])
	Up = num
	Down = num
	TempLetter = ASC_Letter
	TempLetter2 = ASC_Letter
	while TempLetter < 72 and Up < 8:
		if position[0] == 'H' or Up == 8:
			break
		TempLetter = TempLetter + 1
		Up = Up + 1
		moves.append(chr(TempLetter) + str(Up))
	while TempLetter2 > 65 and Down > 0:
		if position[0] == 'A' or Down == 1:
			break
		TempLetter2 = TempLetter2 - 1
		Down = Down - 1
		moves.append(chr(TempLetter2) + str(Down))
	return moves

def TLtBR(position):
	moves = []
	num = int(position[1])
	ASC_Letter = ord(position[0])
	Up = num
	Down = num
	TempLetter = ASC_Letter
	TempLetter2 = ASC_Letter
	while TempLetter < 72 and Down > 1:
		if position[0] == 'H':
			break
		TempLetter = TempLetter + 1
		Down = Down - 1
		moves.append(chr(TempLetter) + str(Down))
	while TempLetter2 > 65 and Up < 8:
		if position[0] == 'A':
			break
		TempLetter2 = TempLetter2 - 1
		Up = Up + 1
		moves.append(chr(TempLetter2) + str(Up))
	return moves

def available_moves(position):
	answer = []
	if not position:
		return answer
	if not isinstance(position, str):
		return answer
	if len(position) != 2:
		return answer
	if int(position[1]) < 1 or int(position[1]) > 8:
		return answer
	if position[0].isdigit():
		return answer
	if ord(position[0]) > 72:
		return answer
	answer.extend(Horizontal(position))
	answer.extend(Vertical(position))
	answer.extend(TLtBR(position))
	answer.extend(TRtBL(position))
	answer.sort()
	return answer


def available_moves(pos):
	if type(pos) != str or pos[0] not in 'ABCDEFGH' or pos[1:] not in '12345678':
		return []
	(i, j) = (int(pos[1]) - 1, 'ABCDEFGH'.index(pos[0]))
	final = sorted(set([f'{i}{pos[1]}' for i in 'ABCDEFGH'] + [f'{pos[0]}{i}' for i in range(1, 9)] + find(i, j) + find(i, j, 1, -1)))
	final.remove(pos)
	return final

def find(x, y, o=1, p=1, A=lambda a, b: f"{'ABCDEFGH'[a]}{b + 1}"):
	while 0 <= x <= 7 and 0 <= y <= 7:
		x -= o
		y -= p
	x += o
	y += p
	li = []
	while 0 <= x < 8 and 0 <= y < 8:
		li.append(A(y, x))
		x += o
		y += p
	return li


def available_moves(position):
	result = []
	try:
		letter = position[0]
		number = int(position[1:])
		if number < 1 or number > 8:
			return result
		if ord(letter) < 65 or ord(letter) > 72:
			return result
		for i in range(65, 73):
			for j in range(1, 9):
				if chr(i) == letter:
					result.append(letter + str(j))
				elif j == number:
					result.append(chr(i) + str(number))
				elif abs(j - number) == abs(i - ord(letter)):
					result.append(chr(i) + str(j))
		result.remove(position)
	except Exception:
		pass
	return result