You are given an array of integers. Your task is to sort odd numbers within the array in ascending order, and even numbers in descending order.

Note that zero is an even number. If you have an empty array, you need to return it.


For example:
```
[5, 3, 2, 8, 1, 4]  -->  [1, 3, 8, 4, 5, 2]

odd numbers ascending:   [1, 3,       5   ]
even numbers descending: [      8, 4,    2]
```

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Sorting

Data structures

Starter code: def sort_array(a):
	

Solutions:
def sort_array(xs):
	es = sorted((x for x in xs if x % 2 == 0))
	os = sorted((x for x in xs if x % 2 != 0), reverse=True)
	return [(es if x % 2 == 0 else os).pop() for x in xs]


def sort_array(a):
	odds = []
	evens = []
	newArray = []
	for i in a:
		if i % 2 == 0:
			evens.append(i)
		else:
			odds.append(i)
	evens.sort()
	evens.reverse()
	odds.sort()
	for i in range(len(a)):
		if a[i] % 2 == 0:
			newArray.append(evens[0])
			evens.pop(0)
		else:
			newArray.append(odds[0])
			odds.pop(0)
	return newArray


def sort_array(a):
	odds = iter(sorted((n for n in a if n % 2)))
	evens = iter(sorted((n for n in a if not n % 2), reverse=True))
	return [next(odds) if n % 2 else next(evens) for n in a]


def sort_array(a):
	(sorted_odd, sorted_even) = (sorted((value for value in a if value & 1)), sorted([value for value in a if not value & 1], reverse=True))
	return [sorted_odd.pop(0) if value & 1 else sorted_even.pop(0) for value in a]


def sort_array(a):
	(e, o) = (sorted((x for x in a if x % 2 ^ 1)), sorted((x for x in a if x % 2), reverse=True))
	return [(o if x % 2 else e).pop() for x in a]


def sort_array(a):
	sorted_odd = sorted([x for x in a if x % 2 == 1], reverse=True)
	sorted_even = sorted([x for x in a if x % 2 == 0])
	out = []
	for x in a:
		if x % 2 == 0:
			out.append(sorted_even.pop())
		else:
			out.append(sorted_odd.pop())
	return out


def sort_array(lst):
	s = sorted(lst)
	even = (n for n in s[::-1] if n & 1 == 0)
	odd = (n for n in s if n & 1)
	return [next(odd if n & 1 else even) for n in lst]


def sort_array(lst):
	(even, odd) = ([], [])
	for n in sorted(lst):
		(odd if n & 1 else even).append(n)
	(even, odd) = (iter(even[::-1]), iter(odd))
	return [next(odd if n & 1 else even) for n in lst]


def sort_array(a):
	lenList = len(a)
	if lenList == 0:
		return []
	(evenNums, oddNums) = ([], [])
	(evenNumLoc, oddNumLoc) = ([], [])
	for i in range(0, lenList, 1):
		if a[i] % 2 == 0:
			evenNums.append(a[i])
			evenNumLoc.append(i)
		else:
			oddNums.append(a[i])
			oddNumLoc.append(i)
	evenNums.sort(reverse=True)
	oddNums.sort()
	sortedList = [0 for _ in range(lenList)]
	totalNumEvens = len(evenNums)
	totalNumOdds = len(oddNums)
	for i in range(0, totalNumEvens, 1):
		sortedList[evenNumLoc[i]] = evenNums[i]
	for i in range(0, totalNumOdds, 1):
		sortedList[oddNumLoc[i]] = oddNums[i]
	return sortedList


from collections import deque

def sort_array(a):
	asc = deque(sorted((x for x in a if x % 2)))
	desc = sorted((x for x in a if not x % 2))
	return [asc.popleft() if x % 2 else desc.pop() for x in a]