I have written this Python program to count the number of each character in a Python string.
def count_chars(s):
counts = [0] * 65536
for c in s:
counts[ord(c)] += 1
return counts
def print_counts(counts):
for i, n in enumerate(counts):
if n > 0:
print(chr(i), '-', n)
if __name__ == '__main__':
print_counts(count_chars('hello, world \u2615'))
Output:
- 2
, - 1
d - 1
e - 1
h - 1
l - 3
o - 2
r - 1
w - 1
☕ - 1
Can this program take care of counting the number of any occurrences of any Unicode character? If not, what can be done to ensure that every possible Unicode character is taken care of?