2020.04.29 TIL

Kay·2020년 4월 29일
0

hash()

파이썬 내장함수로, 객체의 해시 값을 리턴한다.
참고 : Python 3.8.2 문서

collections 모듈의 Counter 클래스

from collections import Counter
Counter('hello')                  [1]
Counter('hello').most_common()    [2]
Counter('hello').most_common(1)   [3]

Counter({'l': 2, 'h': 1, 'e': 1, 'o': 1})   [1]
[('l', 2), ('h', 1), ('e', 1), ('o', 1)]    [2]
[('l', 2)]                                  [3]

[1] 위와 같이 인자로 입력한 단어의 알파벳 갯수를 세어 딕셔너리 형태로 리턴한다.
[2] most_common 메소드를 이용하면 갯수가 많은 순서대로 리턴한다.
[3] 인자를 넣으면 갯수가 많은 순서대로 그 인자만큼 리턴한다.

참고 : https://www.daleseo.com/python-collections-counter/

profile
new blog✨ https://kay-log.tistory.com/

0개의 댓글