[Python] 백준 10807번 - 개수 세기
Python에서 리스트와 map을 활용해 특정 값의 개수를 세는 풀이를 정리했습니다.
For the English version of this post, see here.
[Python] 백준 10807번 - 개수 세기
풀이
1
2
3
4
5
6
7
8
9
10
11
num = int(input())
arr = list(map(int, input().split()))
v = int(input())
cnt = 0
for i in range(num):
if arr[i] == v:
cnt += 1
print(cnt)
map의 결과
- list가 아니라 map 객체임 ex)
<map object at 0x...> - 따라서
list()로 감싸서 list로 만들어줘야함