파이썬 Counter

1 Count 모듈[ | ]

시퀀스 자료형의 데이터 값의 개수를 딕셔너리 형태로 반환

from collections import Counter
text=list("From 1946, the National Advisory Committee for Aeronautics (NACA) had been experimenting with rocket planes such as the supersonic Bell X-1. In the early 1950s, there was a challenge to launch an artificial satellite for the International Geophysical Year (1957–58), resulting in the American Project Vanguard among others. After the Soviet launch of the world's first artificial satellite (Sputnik 1) on October 4, 1957, the attention of the United States turned toward its own fledgling space efforts. The US Congress, alarmed by the perceived threat to national security and technological leadership (known as the 'Sputnik crisis'), urged immediate and swift action; President Dwight D. Eisenhower and his advisers counseled more deliberate measures. On January 12, 1958, NACA organized a 'Special Committee on Space Technology', headed by Guyford Stever.[9] On January 14, 1958, NACA Director Hugh Dryden published 'A National Research Program for Space Technology' stating")
print (text)
#각 데이터값의 개수 출력
print(Counter(text))
#데이터 중 a의 갯수 출력
c=Counter(text)
print(c["a"])

2 Count 생성[ | ]

2.1 딕셔너리[ | ]

딕셔너리 형태 매개변수를 사용하여 Counter 생성가능

from collections import Counter
apple=Counter({'red':4,'blue':2})
print(apple)
print(list(apple.elements()))

2.2 키워드[ | ]

키워드 형태의 매개변수를 사용하여 Counter 생성가능

from collections import Counter
apple=Counter(Normal=4,Critical=6)
print(apple)
print(list(apple.elements()))
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}