Group by Property
Given a list of N integers, group them into sublists such that all integers in a sublist share the same property. The property of an integer x is defined as x % 10 (the last digit). Print the groups in increasing order of their property (last digit). Within each group, the numbers should appear in their original relative order.
Input
The first line contains an integer N. The second line contains N integers, separated by spaces.
Output
Print N lines. Each line contains an integer. The output should consist of all numbers belonging to the group with property 0, followed by all numbers belonging to the group with property 1, and so on, up to property 9. Within each group, numbers must maintain their original relative order.
Constraints
1 <= N <= 200000 0 <= |arr[i]| <= 10^9
Example 1
7 12 5 34 15 7 88 10
10 12 34 5 15 7 88
Numbers are grouped by last digit: {0:[10], 2:[12], 4:[34], 5:[5, 15], 7:[7], 8:[88]}. Output is ordered by last digit: 10, 12, 34, 5, 15, 7, 88.
Example 2
5 1 2 3 4 5
1 2 3 4 5
Simple case with distinct last digits.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
7 12 5 34 15 7 88 10
5 1 2 3 4 5