Sort Even and Odd Numbers
Given a list of N integers, print all the even numbers first, followed by all the odd numbers. Within the even numbers, they should be printed in ascending order. Within the odd numbers, they should also be printed in ascending order. The original input order of elements does not matter for the output, only their parity and magnitude.
Input
The first line contains an integer N (1 <= N <= 1000). The second line contains N space-separated integers.
Output
Print N space-separated integers. The first part of the output should be all even numbers from the input, sorted in ascending order. The second part should be all odd numbers from the input, also sorted in ascending order.
Constraints
1 <= N <= 1000. Each integer is between -1000 and 1000.
Example 1
5 1 2 3 4 5
2 4 1 3 5
Even numbers (2, 4) sorted, then odd numbers (1, 3, 5) sorted.
Example 2
7 -2 5 0 8 -1 3 6
-2 0 6 8 -1 3 5
Even numbers (-2, 0, 6, 8) sorted, then odd numbers (-1, 3, 5) sorted.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 1 2 3 4 5
7 -2 5 0 8 -1 3 6