본문 바로가기 메뉴 바로가기

Good Developer

프로필사진
  • 글쓰기
  • 관리
  • 태그
  • 방명록
  • RSS

Good Developer

검색하기 폼
  • 분류 전체보기 (76)
    • hhplus (6)
    • 개발서적 (4)
    • Error (2)
    • Kafka (1)
    • React (3)
    • Docker (5)
    • Spring (6)
    • Java (27)
    • Project (3)
    • Python (16)
    • DB (3)
    • Github (0)
  • 방명록

counter (1)
[Python] Counter()

collection 라이브러리의 Counter()에 대해 간략하게 알아보도록 하겠습니다.Counter은 반복이 가능한 객체가 있을 때 객체 안에 동일한 값이 몇 개 있는 지를 알려주는 함수입니다. 먼저 Counter 클래스를 사용하기 위해 아래와 같이 import 해줍니다.from collections import Counter1. 리스트 안에 있는 동일한 알파벳을 count 하여 dictionary 값으로 반환해줍니다.test_list = ['a', 'b', 'c', 'a']print(Counter(test_list))# 결과: Counter({'a': 2, 'b': 1, 'c': 1}) 2. 문자열 안에 동일한 알파벳을 count 하여 dictionary 값으로 반환해줍니다.test_count = C..

Python 2022. 12. 6. 17:16
이전 1 다음
이전 다음
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
  • bool
  • operators
  • Upper
  • index
  • Lower
  • combinations
  • find
  • for
  • isalpha
  • If
  • function
  • Python
  • counter
  • Built-in Functions
  • isdigit
  • Lambda
  • zip
  • permutations
  • Method
more
«   2025/05   »
일 월 화 수 목 금 토
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
글 보관함

Blog is powered by Tistory / Designed by Tistory

티스토리툴바