Dictionary lưu cặp key-value. Có thể dùng để đếm tần suất:
Python
dem = {}
for x in [1,2,2,3]:
dem[x] = dem.get(x, 0) + 1Yêu cầu
Nhập dãy số (1 dòng). Đếm số lần xuất hiện của mỗi số, in theo thứ tự tăng dần: {số}: {số_lần}
Ví dụ
Input: 3 1 2 1 3 3 Output: 1: 2 2: 1 3: 3