💡 list.count()와 collections의 counter를 비교하여 보자

< 정답 코드 >
N = int(input())
num = list(map(int,input().split(' ')))
v = int(input())
print(num.count(v))
< 서현님의 코드 >
from sys import stdin as s
from collections import Counter
N = int(s.readline())
A = list(map(int, s.readline().split()))
X = int(s.readline())
cnt = Counter(A)
print(cnt[X])
💡 list.count() vs Counter(list)
from collections import Counter
list = [1, 1, 2, 3, 3]
# list의 count()는 내장함수 이기 떄문에 아무런 선언 없이 사용 가능
# 2
list.count(1)
# Collections의 counter는 import가 필요
# ({1:2, 2:1, 3:2})
result = Counter(list)
=> 리스트 전체를 한번 순회하면서, 해당하는 원소의 갯수를 +1 하는 원리
=> 리스트 전체를 한번 순회하면서, 모든 원소의 갯수를 기록하는 원리
1가지의 원소에 대한 갯수 세기 : count()
여러가지의 원소에 대한 갯수 세기: Counter()