딕셔너리를 이용해서 빈도 수를 저장한 다음 value값을 출력할 수 있도록 코드를 작성했다. 딕셔너리를 이용한 방법도 많이 연습해봐야겠다.
n, d = map(int, input().split())
digit_count = {'0' : 0, '1' : 0, '2' : 0, '3' : 0, '4' : 0, '5' : 0, '6' : 0, '7' : 0, '8' : 0, '9' : 0}
for i in range(1, n+1):
j = str(i)
for t in range(len(j)):
digit_count[j[t]] += 1
print(digit_count[str(d)])
a = {'name': 'pey', 'phone': '010-9999-1234', 'birth': '1118'}
>>> a.items()
dict_items([('name', 'pey'), ('phone', '010-9999-1234'), ('birth', '1118')])
>>> a.values()
dict_values(['pey', '010-9999-1234', '1118'])
>>> a.keys()
dict_keys(['name', 'phone', 'birth'])