python 통계 배열 내 요소 출현 횟수

def get_counts(sequence):
    counts={}
    for x in sequence:
        if x in counts:
            counts[x] += 1
        else:
            counts[x] = 1
    return counts
aa=['a','b','c','d','a','g']
print get_counts(aa)

C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/analyze/a6.py
{'a': 2, 'c': 1, 'b': 1, 'd': 1, 'g': 1}

좋은 웹페이지 즐겨찾기