I have a given Array:
A = [9, 8, 7, 6, 5, 4]
I am implementing count-sort algorithm to sort this array in Python. The numbers in the array are always in the range N.
I got the count of each element and sorting of the list.
count = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1]
sorted = [4, 5, 6, 7, 8, 9]
Now, I want to output the count of each element: For eg:
4 1
5 1
6 1
7 1
8 1
9 1
How do I compare those to lists [count & array]?
Code:
N = int(input())
A = list(map(int, input().split(" ")))
print(A)
m = N + 1
count = [0] * m
for a in A:
# count occurences
count[a] += 1
print(count)
i = 0
for a in range(m):
for c in range(count[a]):
A[i] = a
i += 1
print(A, count)
print([i,j for i,j in zip(A,count)])
I tried to zip, but it didn't work out well. How should I do it?