Digit Frequency
Python
Easy
3 views
Problem Description
A string of digits is provided. Count frequency of each digit 0 to 9 and output 10 integers in one line.
Input Format
One string s (digits only).
Output Format
10 integers counts.
Sample Test Case
Output:
1 1 1 0 0 1 0 0 0 0
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
mp={}
for ch in s:
mp[ch]=mp.get(ch,0)+1
out=[]
for d in '0123456789':
out.append(str(mp.get(d,0)))
sys.stdout.write(' '.join(out))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!