Contact: aviboots(AT)netvision.net.il
43,086 questions
55,959 answers
573 users
from collections import Counter num = 52725510215 freq = Counter(str(num)) print(freq) ''' run: Counter({'5': 4, '2': 3, '1': 2, '7': 1, '0': 1}) '''
from collections import Counter num = 52725510215 freq = Counter(str(num)) for digit in '0123456789': print(digit, freq.get(digit, 0)) ''' run: 0 1 1 2 2 3 3 0 4 0 5 4 6 0 7 1 8 0 9 0 '''
num = 52725510215 freq = {str(d): 0 for d in range(10)} for ch in str(num): freq[ch] += 1 print(freq) ''' run: {'0': 1, '1': 2, '2': 3, '3': 0, '4': 0, '5': 4, '6': 0, '7': 1, '8': 0, '9': 0} '''
num = 52725510215 freq = [0] * 10 for ch in str(num): freq[int(ch)] += 1 print(freq) ''' run: [1, 2, 3, 0, 0, 4, 0, 1, 0, 0] '''