KKG
Programming
KKG
전체 방문자
오늘
어제
  • 전체 글 보기 (84)
    • 회고 (9)
    • Bootcamp (19)
    • Error Handling (2)
    • Kotlin (1)
    • Java (19)
      • Java (14)
      • Spring (1)
      • JPA (2)
      • Link (2)
    • Python (5)
    • 알고리즘 (20)
      • 알고리즘 (4)
      • 백준 (14)
      • 프로그래머스 (1)
      • Link (1)
    • SQL (5)
      • SQL (1)
      • MySQL (4)
    • Web (2)
    • etc (1)

블로그 메뉴

  • 태그
  • 방명록
  • 깃허브

인기 글

티스토리

hELLO · Designed By 정상우.
KKG

Programming

Python

[Python] collections.Counter

2022. 1. 30. 19:01
import collections

li = [1, 2, 3, 4, 5, 6, 7, 8, 7, 9, 1, 3, 5, 7, 9, 1, 5, 9, 0, 1, 10, 100, 10, 1]
cnt = collections.Counter(li)

print(cnt[1])   # 1의 개수: 5
print(cnt[2])   # 2의 개수: 1
print(cnt[3])   # 3의 개수: 2
print(cnt[5])   # 5의 개수: 3
print(cnt[10])  # 10의 개수: 2
print(cnt[100]) # 100의 개수: 1
출력값
5
1
2
3
2
1
    'Python' 카테고리의 다른 글
    • [Python] 중복순열, 중복조합(itertools.product, combinations_with_replacement)
    • [Python] 순열, 조합(itertools.permutations, combinations)
    • [Python] 누적합 itertools.accumulate
    • [Python] 힙 자료구조 Heapqueue

    티스토리툴바