https://www.acmicpc.net/problem/10816
from collections import Counter
import sys
a=int(sys.stdin.readline())
numbers=[]
numbers=list(map(int,sys.stdin.readline().split()))
b=int(sys.stdin.readline())
howmany=list(map(int,sys.stdin.readline().split()))
counter=Counter(numbers)
print(counter)
for i in howmany:
print(counter.__getitem__(i),end=" ")
리스트 내부의 원소가 몇개 있는지 알려주는 라이브러리 Counter을 사용했다.
counter의 형태는 Counter({10: 3, 3: 2, -10: 2, 6: 1, 2: 1, 7: 1}) 딕셔너리 형태이다.
딕셔너리 원소(Key)가 아닌 원소의 갯수 (Value)를 출력하기 위해서는 getitem메소드를 사용해야한다.
'자기개발👨💻 > 코딩 알고리즘' 카테고리의 다른 글
[Java] 백준 11720 숫자의 합 (0) | 2021.09.28 |
---|---|
[Java] 백준11654 아스키코드 (0) | 2021.09.28 |
[python] 백준 2775 부녀회장이 될테야 (0) | 2021.07.29 |
[python] 백준11866 요세푸스문제 0 (0) | 2021.07.12 |
[python] 백준2164 카드2 (0) | 2021.07.08 |
[python] 백준10866 덱 (0) | 2021.07.07 |